Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Deep cloning of arrays with objects
(version: 0)
Comparing performance of:
JSON clone vs loadash clone
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var arr = [{value: 0},{value: 1}, {value: 2}, {value: 3}, {value: 4}, {value: 5}, {value: 6}]
Tests:
JSON clone
JSON.parse(JSON.stringify(arr))
loadash clone
_.cloneDeep(arr)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
JSON clone
loadash clone
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
7 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36
Browser/OS:
Chrome 140 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
JSON clone
2770305.8 Ops/sec
loadash clone
769531.6 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down what is tested in the provided JSON benchmark. **Script Preparation Code** The script preparation code defines an array `arr` containing six objects with a single property `value`. This array will be used as the input for the benchmarks. **Benchmark Definitions** There are two benchmark definitions: 1. **JSON Clone**: The first benchmark definition uses the built-in `JSON.parse(JSON.stringify(arr))` method to create a deep clone of the `arr` array. 2. **Lodash Clone**: The second benchmark definition uses the Lodash library's `_.cloneDeep(arr)` function to create a deep clone of the `arr` array. **Library: Lodash** The Lodash library is a popular JavaScript utility library that provides various functions for tasks such as array manipulation, object transformation, and more. In this case, the `_` object represents the Lodash library, and the `.cloneDeep()` method is used to create a deep clone of the input array. **Special JS Feature or Syntax** Neither of the benchmark definitions uses any special JavaScript features or syntax. They only rely on standard JavaScript methods and libraries. **Comparison of Options** * **Built-in JSON Clone**: The `JSON.parse(JSON.stringify(arr))` method is a simple and widely supported way to create a deep clone of an object. However, it can be slower than the Lodash clone because it involves parsing and stringifying the entire input array. * **Lodash Clone**: The Lodash `_.cloneDeep()` method is designed specifically for creating deep clones of complex data structures like arrays. It is often faster and more efficient than the built-in JSON clone method. **Pros and Cons** * **Built-in JSON Clone**: + Pros: Simple, widely supported, and easy to use. + Cons: Can be slower due to parsing and stringifying the entire input array. * **Lodash Clone**: + Pros: Fast, efficient, and specifically designed for deep cloning complex data structures. + Cons: Requires an additional library dependency (Lodash) and may have a slightly steeper learning curve. **Other Alternatives** If you need to create a deep clone of an array without using the `JSON.parse(JSON.stringify(arr))` method or Lodash, you can also use other libraries like: * **Underscore.js**: Provides a similar `_cloneDeep()` method. * **FastClone**: A lightweight library specifically designed for fast cloning of complex data structures. Alternatively, you can implement your own deep clone function using recursion and iteration. However, this approach may be more error-prone and less efficient than using an existing library like Lodash or FastClone.
Related benchmarks:
Array clone
Shallow Copy Array
Deep cloning of arrays
shallow copy of 6M elements array
Comments
Confirm delete:
Do you really want to delete benchmark?