Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash cloneDeep vs JSON Clone - v3
(version: 0)
Comparing performance of:
Lodash cloneDeep vs Json clone
Created:
5 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...', jayson: { stringify: 'JSON.stringify() method converts a JavaScript value to a JSON string....', parse: 'JSON.parse() method parses a JSON string...', jayson: { stringify: 'JSON.stringify() method converts a JavaScript value to a JSON string....', parse: 'JSON.parse() method parses a JSON string...', } } } }, { 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...', jayson: { stringify: 'JSON.stringify() method converts a JavaScript value to a JSON string....', parse: 'JSON.parse() method parses a JSON string...', jayson: { stringify: 'JSON.stringify() method converts a JavaScript value to a JSON string....', parse: 'JSON.parse() method parses a JSON string...', } }, children: [{ 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...', jayson: { stringify: 'JSON.stringify() method converts a JavaScript value to a JSON string....', parse: 'JSON.parse() method parses a JSON string...', jayson: { stringify: 'JSON.stringify() method converts a JavaScript value to a JSON string....', parse: 'JSON.parse() method parses a JSON string...', } } } }, { 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...', jayson: { stringify: 'JSON.stringify() method converts a JavaScript value to a JSON string....', parse: 'JSON.parse() method parses a JSON string...', jayson: { stringify: 'JSON.stringify() method converts a JavaScript value to a JSON string....', parse: 'JSON.parse() method parses a JSON string...', } } } }, { 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...', jayson: { stringify: 'JSON.stringify() method converts a JavaScript value to a JSON string....', parse: 'JSON.parse() method parses a JSON string...', jayson: { stringify: 'JSON.stringify() method converts a JavaScript value to a JSON string....', parse: 'JSON.parse() method parses a JSON string...', } } } }] } }, { 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...', jayson: { stringify: 'JSON.stringify() method converts a JavaScript value to a JSON string....', parse: 'JSON.parse() method parses a JSON string...', 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);
Json clone
myCopy = JSON.parse(JSON.stringify(MyObject));
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Lodash cloneDeep
Json clone
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll break down the provided benchmark definition, individual test cases, and latest benchmark result. **Benchmark Definition:** The benchmark measures the performance of two methods for creating a deep copy of an object in JavaScript: 1. `JSON.parse(JSON.stringify(MyObject))` 2. `_._cloneDeep(MyObject)` **Options being compared:** * **JSON.parse(JSON.stringify(MyObject))**: This method uses the `JSON` object to create a deep copy of the input object `MyObject`. It works by first converting the entire object to a JSON string using `JSON.stringify()`, and then parsing that string back into an object using `JSON.parse()`. * **Lodash's `_cloneDeep(MyObject)`**: This method uses the Lodash library to create a deep copy of the input object `MyObject`. It is designed to handle complex data structures, such as arrays and objects with nested properties. **Pros and Cons:** * **JSON.parse(JSON.stringify())**: + Pros: Simple, widely supported, and relatively fast. + Cons: Can be slower for very large objects due to the overhead of string conversion. Also, it only works with JSON-serializable data, which can limit its use cases. * **Lodash's `_cloneDeep()`**: + Pros: Handles complex data structures more robustly, and is generally faster than `JSON.parse(JSON.stringify())` for large objects. It also provides a more flexible way to create deep copies. + Cons: Requires the Lodash library, which can add additional overhead. **Library used:** The benchmark uses Lodash (version 4.17.5) for its `_cloneDeep()` method. **Special JS feature or syntax:** None mentioned in the provided code. **Other notes:** * The benchmark is designed to measure the performance of these two methods on a specific input object `MyObject`. * The latest benchmark result shows that Lodash's `_cloneDeep()` method outperforms `JSON.parse(JSON.stringify())` for this particular test case. In summary, the benchmark measures the performance of two methods for creating deep copies in JavaScript: `JSON.parse(JSON.stringify())` and Lodash's `_cloneDeep()`. It compares their performance on a specific input object and shows that Lodash's method is generally faster.
Related benchmarks:
lodash clonedeep vs json.parse(stringify()) vs recursivecopy vs shallowcopy
Lodash cloneDeep vs JSON Clone (Deeper object)
lodash clonedeep vs json.parse(stringify()) vs recursivecopy new big
Plain Json: lodash clonedeep vs json.parse(stringify())
Lodash cloneDeep vs structuredClone vs recursiveDeepCopy vs JSON clone with a more deep test
Comments
Confirm delete:
Do you really want to delete benchmark?