Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
deep clone JSON
(version: 0)
Comparing performance of:
json stringify vs lodash deep clone vs Object.assign vs Ramda clone
Created:
8 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="//cdnjs.cloudflare.com/ajax/libs/ramda/0.25.0/ramda.min.js"></script> <script src='https://cdn.jsdelivr.net/npm/lodash@4.17.10/lodash.min.js'></script>
Tests:
json stringify
var obj = {a: "hello", c: "test", po: 33, arr: [1, 2, 3, 4], anotherObj: {a: 33, str: "whazzup"}}; var obj2 = JSON.parse(JSON.stringify(obj));
lodash deep clone
var obj = {a: "hello", c: "test", po: 33, arr: [1, 2, 3, 4], anotherObj: {a: 33, str: "whazzup"}}; var obj2 = _.clone(obj, true);
Object.assign
var obj = {a: "hello", c: "test", po: 33, arr: [1, 2, 3, 4], anotherObj: {a: 33, str: "whazzup"}}; var obj2 = Object.assign({}, obj);
Ramda clone
var obj = {a: "hello", c: "test", po: 33, arr: [1, 2, 3, 4], anotherObj: {a: 33, str: "whazzup"}}; var obj2 = R.clone(obj, true);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
json stringify
lodash deep clone
Object.assign
Ramda clone
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.1:latest
, generated one year ago):
Let's dive into the benchmark definition and test cases. **Benchmark Definition:** The benchmark is called "deep clone JSON". This means we're testing different methods for creating a deep copy of a JavaScript object, which involves cloning all nested objects recursively. **Test Cases:** 1. **JSON.stringify()** * This method is part of the JavaScript language itself. * It converts an object to a JSON string and then parses it back to create a new object. * Pros: + No external dependencies required. + Works on most browsers and environments. * Cons: - Can be slow for large or deeply nested objects due to the parsing overhead. 2. **Lodash _.clone()** * This method is part of the popular Lodash library (version 4.17.10). * It creates a deep copy of an object, including its nested structures. * Pros: + Provides additional features like deep merging and cloning with options. + Well-maintained and widely used library. * Cons: - Requires the Lodash library to be loaded. 3. **Object.assign()** * This method is part of the JavaScript language itself (since ES6). * It creates a new object by assigning properties from an existing object or multiple objects. * Pros: + No external dependencies required. - Can be used for shallow copying, but not recommended for deep cloning due to its limitations. 4. **Ramda R.clone()** * This method is part of the popular Ramda library (version 0.25.0). * It creates a deep copy of an object, including its nested structures. * Pros: + Provides additional features like deep merging and cloning with options. - Well-maintained and widely used library. **Other Alternatives:** While not tested in this specific benchmark, other alternatives for deep copying objects include: * **lodash.deepClone()**: A more modern method in Lodash (version 4.17.10) specifically designed for deep cloning. * **jsondeepcopy()**: A separate library that provides a deep clone function. * **structuredClone()**: A newer JavaScript feature (since ES2022) that allows deep copying of objects, but might not be widely supported yet. Keep in mind that each method has its trade-offs, and the best choice depends on your specific use case and requirements.
Related benchmarks:
Deep Clone Performance - JSON vs Lodash vs Ramda vs Native
lodash includes vs ramda includes
lodash merge vs deepmerge vs ramda
Lodash vs Ramda fromPairs
Deep clone: lodash vs ramda
Comments
Confirm delete:
Do you really want to delete benchmark?