Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Clone Deep vs JSON Parse
(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.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);
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:
Run details:
(Test run date:
one month ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36
Browser/OS:
Chrome 146 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash cloneDeep
1824492.2 Ops/sec
Json clone
1838083.2 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll break down the benchmark and its results for you. **Benchmark Overview** The benchmark compares two approaches to create a deep copy of an object in JavaScript: 1. Using the `lodash` library's `cloneDeep()` function 2. Using the built-in `JSON.parse(JSON.stringify())` method **Options Compared** * **Lodash cloneDeep**: Uses the `_.cloneDeep()` function from the Lodash library to create a deep copy of the object. + Pros: Provides a well-tested and widely used implementation of deep cloning, which can be more efficient than manual implementation. + Cons: Adds an external dependency (Lodash), which may not be included in all environments. * **Json clone**: Uses the `JSON.parse(JSON.stringify())` method to create a deep copy of the object. + Pros: Built-in and widely supported, with minimal dependencies. However, it may not work correctly for all types of objects or values (e.g., circular references). + Cons: Can be slower and more memory-intensive than `_.cloneDeep()`, especially for large objects. **Library** The Lodash library is used in the first test case (`Lodash cloneDeep`). Lodash is a popular utility library that provides a wide range of functions for tasks like array manipulation, object transformation, and more. In this case, it's used to provide a convenient and efficient implementation of deep cloning. **Other Considerations** * **Manual Implementation**: Creating a deep copy manually would require writing custom code to handle different types of objects and values. While possible, it's often less efficient and error-prone than using a library like Lodash. * **Circular References**: The `JSON.parse(JSON.stringify())` method will not work correctly for objects with circular references (i.e., properties that reference the same object). In contrast, `_.cloneDeep()` can handle these cases. **Other Alternatives** If you don't want to use an external library like Lodash, you could consider implementing your own deep cloning function using JavaScript's built-in `Object.assign()` and recursive functions. However, this approach would require more code and may not be as efficient or reliable as `_.cloneDeep()`.
Related benchmarks:
Lodash cloneDeep vs JSON Clone with huge object
Lodash cloneDeep vs clone
Lodash cloneDeep vs JSON Clone vs Obj Clone
Lodash cloneDeep vs JSON.parse(JSON.stringify())
Lodash vs structured Clone vs json parse
Comments
Confirm delete:
Do you really want to delete benchmark?