Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
structuredClone vs _.cloneDeep vs JSON - 1
(version: 0)
compare array copy/clone methods sdfewfe
Comparing performance of:
Lodash cloneDeep vs Native JSON parse vs structuredClone
Created:
one year 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 testArray = [{ description: 'Random description.', testNumber: 123456789, testBoolean: true, testObject: { testString: 'test string', testNumber: 12345 }, testArray: [{ myName: 'test name', myNumber: 123245 }] }, { description: 'Random description.', testNumber: 123456789, testBoolean: true, testObject: { testString: 'test string', testNumber: 12345 }, testArray: [{ myName: 'test name', myNumber: 123245 }] }];
Tests:
Lodash cloneDeep
testCopy = _.cloneDeep(testArray);
Native JSON parse
testCopy = JSON.parse(JSON.stringify(testArray));
structuredClone
testCopy = structuredClone(testArray);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Lodash cloneDeep
Native JSON parse
structuredClone
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36
Browser/OS:
Chrome 123 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash cloneDeep
260078.0 Ops/sec
Native JSON parse
333232.8 Ops/sec
structuredClone
156500.1 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 is being tested?** The benchmark is comparing three different methods for copying or cloning arrays in JavaScript: 1. `structuredClone` 2. `_` (Lodash) `cloneDeep` 3. Native JSON parsing using `JSON.parse(JSON.stringify())` **Options compared:** * `structuredClone`: a new function introduced in ECMAScript 2020, which creates a deep copy of an object. * `_.cloneDeep` (Lodash): a utility function that creates a deep copy of an object. * Native JSON parsing using `JSON.parse(JSON.stringify())`: a built-in method for cloning objects by serializing them to a string and then parsing the string back into an object. **Pros and Cons:** * `structuredClone`: + Pros: fast, efficient, and easy to use. + Cons: not widely supported in older browsers or Node.js versions, as it's a relatively new standard. * `_` (Lodash) `cloneDeep`: + Pros: widely supported, easy to use, and provides additional features like preserving circular references. + Cons: larger bundle size compared to native methods. * Native JSON parsing using `JSON.parse(JSON.stringify())`: + Pros: small bundle size, widely supported, and easy to use. + Cons: can be slow for large objects due to the overhead of serializing and parsing. **Library/Lodash purpose:** The Lodash library is a popular utility library that provides a wide range of functions for tasks like array manipulation, object cloning, and more. In this benchmark, `_` (Lodash) `cloneDeep` is used to create a deep copy of the input array. **Special JS feature/syntax:** There is no special JavaScript feature or syntax being tested in this benchmark. The focus is on comparing the performance of different cloning methods. **Other alternatives:** If you need to clone arrays, other alternatives include: * `Array.prototype.slice()`: creates a shallow copy of an array. * `Array.prototype.concat()`: creates a new array with elements from the original array and possibly additional elements. * Other libraries like `lodash-es` (a smaller version of Lodash) or `json-stringify-safe` for cloning objects. Keep in mind that the choice of cloning method depends on your specific use case and requirements.
Related benchmarks:
Lodash cloneDeep vs native cloneDeep vs dom cloneDeep
Lodash cloneDeep vs native cloneDeep vs structuredClone
Lodash cloneDeep vs custom cloneDeep vs structuredClone
Lodash cloneDeep vs native cloneDeep - deepclone only
Lodash cloneDeep vs native cloneDeep vs native structuredClone
Comments
Confirm delete:
Do you really want to delete benchmark?