Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash cloneDeep vs JSON Clone with huge object
(version: 0)
Comparing performance of:
Lodash cloneDeep vs Json clone
Created:
7 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'.repeat(300000), 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:
2 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36
Browser/OS:
Chrome 145 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash cloneDeep
1775664.9 Ops/sec
Json clone
444.7 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and explain what's being tested. **What's being tested:** The benchmark is comparing two approaches to create a deep copy of a large object: 1. `_.cloneDeep(MyObject)` using Lodash 2. `JSON.parse(JSON.stringify(MyObject))` These two methods are used to duplicate an object, which includes arrays and objects as properties. **Options compared:** * **Lodash**: A popular utility library for JavaScript that provides various functions for tasks like array manipulation, object cloning, and more. + Pros: - Well-maintained and widely adopted - Provides a simple and concise way to clone objects + Cons: - Adds an external dependency (Lodash) - May have performance implications due to the overhead of the library * **Native `JSON.parse(JSON.stringify())`**: A built-in JavaScript method for cloning objects. + Pros: - No external dependencies or overhead - Native implementation, which is often faster than third-party libraries + Cons: - Not designed specifically for deep copying objects, which can lead to issues with circular references and complex data structures. **Other considerations:** * The benchmark uses a large object (`MyObject`) with 300,000 repeated strings (`myNumber`), nested objects (`jayson`), and other properties. This helps to stress the cloning mechanisms and demonstrate their performance differences. * The `Html Preparation Code` includes a link to Lodash, which is necessary for the first test case. **Library used:** Lodash (version 4.17.5) is used in the benchmarking process. It provides the `_.cloneDeep()` function, which creates a deep copy of an object. **Special JS feature or syntax:** None mentioned in this specific benchmark. **Benchmark preparation code:** The code prepares two objects: * `MyObject`: A nested object with various properties, including arrays and strings. * `myCopy`: An empty variable that will receive the cloned object (or a new copy). **Individual test cases:** Two test cases are defined: 1. `Lodash cloneDeep`: Creates a deep copy of `MyObject` using Lodash's `_.cloneDeep()` function. 2. `Json clone`: Creates a deep copy of `MyObject` using the native `JSON.parse(JSON.stringify())` method. **Latest benchmark result:** The latest results show that: * Chrome 116, running on a Mac OS X 10.15.7 machine, executed the Lodash cloning function approximately 735,118 times per second. * Chrome 116, running on the same machine, executed the JSON cloning function approximately 79,355 times per second. Keep in mind that these results are specific to this particular benchmark and environment. The actual performance differences between these methods may vary depending on other factors, such as the specific use case, data size, and JavaScript engine being used.
Related benchmarks:
Lodash 2.2.0 cloneDeep vs JSON Clone w/ large nested object
cloneDeep vs JSON stringify + parse (long arr)
lodash clonedeep vs json.parse(stringify()) vs recursivecopy new big
Lodash cloneDeep vs JSON parse
Comments
Confirm delete:
Do you really want to delete benchmark?