Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
structuredClone test perso
(version: 0)
compare array copy/clone methods sdfewfe
Comparing performance of:
Lodash cloneDeep vs Native JSON parse vs structuredClone
Created:
3 years 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:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'd be happy to help you understand what's being tested in the provided benchmark. **What is being tested?** The benchmark is testing three different methods for copying or cloning an array: `structuredClone`, `JSON.parse(JSON.stringify())`, and `lodash.cloneDeep()`. **Options compared** * `structuredClone()`: This method is part of the WebAssembly (WASM) specification, which allows for efficient serialization and deserialization of JavaScript objects. * `JSON.parse(JSON.stringify())`: This is a built-in method in JavaScript that creates a deep copy of an object by serializing it to a JSON string and then parsing it back into an object. * `lodash.cloneDeep()`: This is a utility function from the Lodash library, which provides a more efficient and flexible way to create deep copies of objects. **Pros and cons of each approach** * `structuredClone()`: + Pros: Efficient serialization and deserialization, can handle complex data structures. + Cons: Only supported in modern browsers (Chrome 112 and above) and Node.js. May not work with older browsers or environments. * `JSON.parse(JSON.stringify())`: + Pros: Widely supported across all browsers and environments. Easy to implement. + Cons: Can be slow for large objects, may not handle circular references correctly. * `lodash.cloneDeep()`: + Pros: Efficient and flexible way to create deep copies of objects. Handles circular references correctly. + Cons: Requires an additional library (Lodash) and can add complexity to the codebase. **Library usage** The benchmark uses the Lodash library (`lodash.min.js`) to implement the `cloneDeep()` function. **Special JS feature or syntax** None mentioned in this specific benchmark. However, it's worth noting that the `structuredClone()` method was introduced in the WebAssembly specification and is only supported in modern browsers (Chrome 112 and above) and Node.js. **Alternatives** If you need to clone an array in JavaScript, you can also consider using other libraries or methods, such as: * `Array.prototype.slice()`: Creates a shallow copy of an array. * `Array.prototype.concat()`: Creates a new array with the elements of another array. * `Object.assign()`: Copies the values of an object to another object. However, these methods may not provide the same level of efficiency and flexibility as `structuredClone()` or `lodash.cloneDeep()`.
Related benchmarks:
Lodash cloneDeep vs native cloneDeep vs structuredClone
Lodash cloneDeep vs custom cloneDeep vs structuredClone
Lodash cloneDeep vs native cloneDeep vs native structuredClone
dsdadsastructuredClone test
Comments
Confirm delete:
Do you really want to delete benchmark?