Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash deep clone (v4.17.20) vs JSON.stringfy
(version: 0)
Comparing performance of:
Lodash deep clone vs JSON.stringfy
Created:
5 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdn.jsdelivr.net/npm/lodash@4.17.20/lodash.min.js'></script>
Script Preparation code:
window.obj = { foo: 'some string', bar: 'another', subObj: { hey: 'you', what: 'are you doing' } }
Tests:
Lodash deep clone
const objClone = _.cloneDeep(window.obj);
JSON.stringfy
const objClone = JSON.parse(JSON.stringify(window.obj));
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Lodash deep clone
JSON.stringfy
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/124.0.0.0 Safari/537.36
Browser/OS:
Chrome 124 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash deep clone
1986753.4 Ops/sec
JSON.stringfy
1775136.5 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. **Benchmark Overview** The benchmark compares the performance of two approaches for creating a deep clone of an object: Lodash's `cloneDeep` function and JSON stringification using `JSON.parse(JSON.stringify())`. **Options Being Compared** There are two options being compared: 1. **Lodash's `cloneDeep` function**: This is a utility function from the Lodash library that creates a deep copy of an object. 2. **JSON stringification with `JSON.parse(JSON.stringify())`**: This approach serializes the original object to a JSON string, and then parses the resulting string back into an object. **Pros and Cons** 1. **Lodash's `cloneDeep` function**: * Pros: + Creates a deep copy of the object, preserving all nested properties and their values. + Often faster than manual serialization and parsing. * Cons: + Requires including the Lodash library, which may add overhead for some use cases. 2. **JSON stringification with `JSON.parse(JSON.stringify())`**: * Pros: + Only requires a lightweight JSON parser (built-in in modern browsers). + Can be faster for very large objects or in situations where memory is limited. * Cons: + May not preserve all nested properties and their values, as some data types may not be serializable. + Requires manual handling of circular references. **Library: Lodash** Lodash is a popular JavaScript utility library that provides a wide range of functions for tasks such as array manipulation, object manipulation, and string manipulation. The `cloneDeep` function is one of the many utilities provided by Lodash, designed to create deep copies of objects. **Special JS Feature/Syntax** There doesn't appear to be any special JavaScript features or syntax being used in this benchmark. **Other Alternatives** If you need a faster alternative to `JSON.parse(JSON.stringify())`, you might consider using: 1. **Object.assign()**: This method creates a new object by copying all own enumerable properties from one or more source objects. 2. **Array.prototype.slice() + JSON.parse()**: You can use `Array.prototype.slice()` to create an array copy of the object's values, and then parse the resulting array into an object using `JSON.parse()`. 3. **Manual serialization/deserialization**: For very large objects or performance-critical applications, you might consider implementing your own manual serialization and deserialization mechanism. Keep in mind that these alternatives may not be as convenient or efficient as Lodash's `cloneDeep` function, but they can provide a good starting point for customizing the cloning process to suit your specific needs.
Related benchmarks:
Lodash deep clone vs JSON.stringfy
Lodash deep clone vs Spread Clone
Lodash deeper clone vs Spread Clone
Fair Lodash deep clone vs Spread Clone
Comments
Confirm delete:
Do you really want to delete benchmark?