Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash (4.17.11) cloneDeep vs JSON Clone
(version: 0)
Comparing performance of:
Lodash cloneDeep vs Json clone
Created:
6 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/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);
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.1:latest
, generated one year ago):
Let's dive into the benchmark. **What is being tested?** The test case is comparing two different ways to create a deep copy of an object in JavaScript: 1. Using the `cloneDeep` function from Lodash (a popular utility library). 2. Using the built-in `JSON.parse(JSON.stringify(obj))` method. **What options are compared?** In this benchmark, we're testing the execution speed (Executions Per Second) of two different approaches to create a deep copy of an object: 1. **Lodash cloneDeep**: This uses the `_cloneDeep` function from Lodash to create a deep copy of the `MyObject` object. 2. **JSON Clone**: This uses the combination of `JSON.stringify()` and `JSON.parse()` to create a deep copy of the `MyObject` object. **Pros/Cons of each approach:** * **Lodash cloneDeep**: + Pros: Lodash's `cloneDeep` function is specifically designed for deep cloning, which can be more efficient than using `JSON.stringify()` and `JSON.parse()`. + Cons: Requires including the Lodash library. * **JSON Clone**: + Pros: No external library required. + Cons: Can be slower due to the overhead of stringifying and parsing JSON. **Library and its purpose** In this test case, the Lodash library is used. Lodash is a popular JavaScript utility library that provides a wide range of functional programming helpers for tasks like data manipulation, array filtering, and more. In this specific case, the `cloneDeep` function from Lodash is used to create a deep copy of an object. **Special JS feature or syntax** No special JavaScript features or syntax are used in this test case. The code is standard JavaScript with no experimental or proprietary syntax. **Other alternatives** If you don't want to use Lodash, other alternatives for deep cloning include: * `structuredClone()` (a modern browser API): This method creates a deep copy of an object and is supported by most modern browsers. * A custom implementation using recursion: You can write your own function to create a deep copy of an object using recursive calls. Keep in mind that the performance characteristics may vary depending on the specific use case and the size of the objects being cloned.
Related benchmarks:
Lodash cloneDeep vs JSON Clone with huge object
Lodash deep clone vs JSON.stringfy
Lodash cloneDeep vs JSON Clone with Array
Lodash (4.17.11) cloneDeep vs JSON Clone vs structuredClone
Lodash cloneDeep vs JSON parse
Comments
Confirm delete:
Do you really want to delete benchmark?