Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash cloneDeep vs JSON Clone vs Lodash clone
(version: 0)
Comparing performance of:
Lodash cloneDeep vs Json clone vs Lodash clone
Created:
4 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));
Lodash clone
myCopy = _.cloneDeep(MyObject);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Lodash cloneDeep
Json clone
Lodash clone
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Browser/OS:
Chrome 131 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash cloneDeep
871094.1 Ops/sec
Json clone
818634.8 Ops/sec
Lodash clone
823942.9 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what's being tested. **Benchmark Definition** The test is comparing three different approaches to create a deep copy of an object: 1. `_.cloneDeep(MyObject)` from Lodash 2. `JSON.parse(JSON.stringify(MyObject))` 3. `_.clone(MyObject)` from Lodash These functions are designed to preserve the structure and values of the original object. **Options Compared** The three options being compared are: * `_.cloneDeep(MyObject)`: Uses Lodash's `cloneDeep` function, which is a deep clone that recursively copies all properties of the original object. * `JSON.parse(JSON.stringify(MyObject))`: Uses JSON serialization and deserialization to create a copy of the object. This method only works for objects with simple values (e.g., numbers, strings) and can be slow or fail for complex data structures. * `_.clone(MyObject)`: Uses Lodash's `clone` function, which is a shallow clone that only copies the top-level properties of the original object. **Pros and Cons** Here's a brief summary: * `_.cloneDeep(MyObject)`: + Pros: Preserves the entire structure and values of the original object. + Cons: May be slower than other methods, especially for large objects. * `JSON.parse(JSON.stringify(MyObject))`: + Pros: Lightweight and easy to implement. + Cons: Only works for simple data structures, can fail with complex objects, and may be slow. * `_.clone(MyObject)`: + Pros: Fast and efficient for shallow clones. + Cons: Only preserves top-level properties, not the entire structure. **Library: Lodash** Lodash is a popular JavaScript utility library that provides a wide range of functions for tasks like array manipulation, object cloning, and more. The `cloneDeep` and `clone` functions in this benchmark are part of the Lodash library. **Special JS Feature or Syntax** There doesn't appear to be any special JavaScript features or syntax being used in this benchmark. However, it's worth noting that some of these functions may rely on internal implementation details or assumptions about JavaScript objects and arrays. **Other Alternatives** Some alternative approaches to deep copying objects might include: * Using a library like `immer` for immutable data structures * Implementing a custom deep copy function using recursion and array creation * Using a library like `deepcopy` from the `lodash-es` package (if you're targeting modern browsers with support for ES6+ features) Keep in mind that this benchmark is designed to compare specific implementations of object cloning, so these alternative approaches might not be directly relevant to this particular test.
Related benchmarks:
Lodash cloneDeep vs JSON Clone with huge object
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?