Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
testeachone
(version: 0)
https://developer.mozilla.org/en-US/docs/Web/API/structuredClone
Comparing performance of:
Lodash cloneDeep vs Native structuredClone vs JSON stringify/parse
Created:
2 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
var MyObject = { description: 'Creates a deep copy of source, which should be an object or an array.', myNumber: 123456789, myBoolean: true, jayson: { stringify: 'JSON.stringify() method converts a JavaScript value to a JSON string....', parse: 'JSON.parse() method parses a JSON string...' } }; var myCopy = null;
Tests:
Lodash cloneDeep
myCopy = _.cloneDeep(MyObject);
Native structuredClone
myCopy = structuredClone(MyObject);
JSON stringify/parse
myCopy = JSON.parse(JSON.stringify(MyObject))
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Lodash cloneDeep
Native structuredClone
JSON stringify/parse
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:125.0) Gecko/20100101 Firefox/125.0
Browser/OS:
Firefox 125 on Mac OS X 10.15
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash cloneDeep
1932494.9 Ops/sec
Native structuredClone
1105791.9 Ops/sec
JSON stringify/parse
1815978.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Overview** The provided JSON represents a JavaScript microbenchmark on MeasureThat.net, where users can compare the performance of different approaches to create a deep copy of an object. The benchmark tests three methods: Lodash's `cloneDeep` function, Mozilla's native `structuredClone` function, and the traditional method using `JSON.stringify` and `JSON.parse`. **Options compared** The three options being compared are: 1. **Lodash cloneDeep**: A popular library function that creates a deep copy of an object. 2. **Native structuredClone**: A newly introduced function in Mozilla's JavaScript engine (introduced in Gecko 125) that creates a deep copy of an object using a unique algorithm. 3. **JSON stringify/parse**: A traditional method that uses `JSON.stringify` to serialize the object and then parses it back into a new object. **Pros and Cons** 1. **Lodash cloneDeep**: * Pros: Fast, reliable, and widely supported by third-party libraries. * Cons: Requires an additional library dependency, may have memory overhead due to serialization. 2. **Native structuredClone**: * Pros: Native implementation, potentially faster than Lodash's implementation, uses less memory due to no serialization. * Cons: Limited support outside of Mozilla's JavaScript engine, not yet widely adopted by third-party libraries. 3. **JSON stringify/parse**: * Pros: Widely supported and easily implemented without additional dependencies. * Cons: Slower than Lodash's implementation, may have performance issues with large objects due to serialization. **Library usage** The benchmark uses the `lodash` library, which provides the `cloneDeep` function. The script preparation code includes a script tag that loads the `lodash.min.js` file from a CDN. **Special JS feature/syntax** There is no special JavaScript feature or syntax being used in this benchmark. **Other alternatives** If you're looking for alternative deep copy methods, some options include: 1. **Array.prototype.slice()**: Creates a shallow copy of an array. 2. **Object.assign()**: Creates a new object with the same properties as an existing object. 3. **jQuery's $.extend()**: A jQuery-specific method that creates a new object with the same properties as an existing object. Keep in mind that these alternatives may not provide deep copies, and some may have performance implications depending on the use case.
Related benchmarks:
Lodash cloneDeep vs structuredClone vs JSON.stringify (small object)
teste simple deep copy
teste simple deep copy 2
teste simple deep copy 3
Lodash cloneDeep vs structuredClone vs Json.stringify
Comments
Confirm delete:
Do you really want to delete benchmark?