Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Plain Json: lodash clonedeep vs json.parse(stringify())
(version: 0)
One more case to check
Comparing performance of:
Lodash cloneDeep vs Json clone
Created:
2 years ago
by:
Registered User
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, stringify: 'JSON.stringify() method converts a JavaScript value to a JSON string....', parse: 'JSON.parse() method parses a JSON string...', description1: 'Creates a deep copy of source, which should be an object or an array.', myNumber1: 123456789, myBoolean1: true, stringify1: 'JSON.stringify() method converts a JavaScript value to a JSON string....', parse1: 'JSON.parse() method parses a JSON string...', description2: 'Creates a deep copy of source, which should be an object or an array.', myNumber2: 123456789, myBoolean2: true, stringify2: 'JSON.stringify() method converts a JavaScript value to a JSON string....', parse2: 'JSON.parse() method parses a JSON string...', description3: 'Creates a deep copy of source, which should be an object or an array.', myNumber3: 123456789, myBoolean3: true, stringify3: 'JSON.stringify() method converts a JavaScript value to a JSON string....', parse3: 'JSON.parse() method parses a JSON string...', description4: 'Creates a deep copy of source, which should be an object or an array.', myNumber4: 123456789, myBoolean4: true, stringify4: 'JSON.stringify() method converts a JavaScript value to a JSON string....', parse4: '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 year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36 Edg/135.0.0.0
Browser/OS:
Chrome 135 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash cloneDeep
224601.8 Ops/sec
Json clone
185219.9 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Measuring performance and efficiency in JavaScript is crucial for developing robust, scalable applications. **Benchmark Overview** The provided benchmark, named "Plain Json: lodash clonedeep vs json.parse(stringify())", compares the performance of two methods to create a deep copy of an object: `_.cloneDeep` from the Lodash library and `JSON.parse(JSON.stringify(MyObject))`. **Methods Compared** 1. **Lodash's `_.cloneDeep()`**: This method creates a deep copy of the source object, which is useful when you need to preserve the structure and values of the original object. 2. **`JSON.parse(JSON.stringify(MyObject))`**: This method uses JSON serialization and deserialization to create a new object that is a deep copy of the original `MyObject`. However, it's worth noting that this method does not preserve all the complexities of the original object, such as functions, undefined values, or symbols. **Pros and Cons** **Lodash's `_.cloneDeep()`** Pros: * Preserves the structure and values of the original object. * Handles complex objects, including functions, undefined values, and symbols. * Can be more efficient for large datasets. Cons: * Requires Lodash library inclusion (included in this benchmark). * May have overhead due to additional dependencies. **`JSON.parse(JSON.stringify(MyObject))`** Pros: * Simple and lightweight implementation. * Fast serialization and deserialization. Cons: * Does not preserve all complexities of the original object, such as functions or undefined values. * Can be slower for large datasets. **Library: Lodash's `_.cloneDeep()`** Lodash is a popular JavaScript utility library that provides a wide range of functional programming helpers. `_.cloneDeep()` is a part of this library and is specifically designed to create deep copies of objects while preserving their structure and values. **Special JS Feature or Syntax (Not Applicable)** There are no special JavaScript features or syntaxes being used in this benchmark. **Benchmark Preparation Code** The preparation code creates an object `MyObject` with multiple properties, including some that are not serialized properly by `JSON.stringify()`, such as functions and undefined values. The script then defines a copy of this object using both methods (`_.cloneDeep()` and `JSON.parse(JSON.stringify(MyObject))`) and assigns it to the `myCopy` variable. **Other Alternatives** If you're looking for alternative methods to create deep copies in JavaScript, some options include: * Using the `Array.prototype.slice()` method or the spread operator (`...`) to create a shallow copy. * Implementing your own deep copying logic using recursive functions or a library like Immutable.js. * Using other libraries like Ramda's `cloneDeep` function. Keep in mind that each method has its trade-offs and may be better suited for specific use cases.
Related benchmarks:
Lodash cloneDeep vs JSON Clone Array
lodash clonedeep vs json.parse(stringify()) vs recursivecopy new big
Lodash cloneDeep vs structuredClone vs recursiveDeepCopy vs JSON clone with a more deep test
lodash clonedeep vs json.parse(stringify()) vs recursivecopy heavy
Comments
Confirm delete:
Do you really want to delete benchmark?