Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash cloneDeep vs JSON Clone (very big 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.11/lodash.min.js'></script>
Script Preparation code:
var MyObject = {}; // Iterate to big object 100 000 times for (var i = 0; i < 100000; i++) { MyObject['prop' + i] = { 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 (X11; Linux x86_64; rv:148.0) Gecko/20100101 Firefox/148.0
Browser/OS:
Firefox 148 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash cloneDeep
1.6 Ops/sec
Json clone
2.8 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 benchmark consists of two test cases: 1. `Lodash cloneDeep` 2. `JSON Clone` Both tests aim to measure the performance difference between two methods for creating a deep copy of a large object: Lodash's `cloneDeep` function and the built-in JavaScript method `JSON.parse(JSON.stringify())`. **What's being tested?** The benchmark is testing the following options: * **Lodash cloneDeep**: A library-based approach that uses the `cloneDeep` function from the Lodash library to create a deep copy of the object. * **JSON Clone**: A built-in JavaScript method (`JSON.parse(JSON.stringify())`) that creates a shallow copy of an object and then recursively clones its properties. **Pros and Cons** **Lodash cloneDeep** Pros: * Pros: Lodash's `cloneDeep` function is designed to create deep copies of objects, which can be more efficient than the built-in `JSON.parse(JSON.stringify())` method. * Cons: + Requires loading an additional library (Lodash), which may add overhead. + May have some additional complexity due to its internal implementation. **JSON Clone** Pros: * Pros: Built-in and lightweight, no additional library required. * Cons: + Creates a shallow copy first, then recursively clones properties, which can lead to more copies being created than necessary. + Can be slower for very large objects due to the recursive cloning process. **Other Considerations** Both approaches have their trade-offs. The Lodash approach provides a more efficient deep copying solution but requires additional setup (loading the library). The built-in JavaScript method is simpler and doesn't require any external libraries, but may create unnecessary copies and be slower for very large objects. **Library Used: Lodash** Lodash is a popular JavaScript utility library that provides various functions for tasks like array manipulation, object transformation, and more. In this case, the `cloneDeep` function is used to create deep copies of objects. **Special JS Feature/Syntax** Neither test case uses any special JavaScript features or syntax. The benchmark focuses on measuring the performance difference between two existing methods for creating a deep copy of an object. **Alternatives** Other alternatives for creating deep copies in JavaScript include: * Using `Array.prototype.slice()` and `Object.assign()` to create shallow copies, followed by recursive cloning. * Using libraries like Immer or Ramda, which provide similar functionality to Lodash but with different APIs and features. * Implementing a custom deep copying function using recursion or iteration. Keep in mind that the choice of approach depends on the specific use case and performance requirements.
Related benchmarks:
Lodash cloneDeep vs JSON Clone with huge object
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?