Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
cloneDeep vs structuredClone
(version: 0)
Comparing performance of:
lodash 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 MyObject = { description: 'Creates a deep copy of source, which should be an object or an array.', myNumber: 123456789, myBoolean: true, jayson: { stringify: 'JSON.stringify() method converts a JavaScript value to a JSON string....', parse: 'JSON.parse() method parses a JSON string...',jayson: { stringify: 'JSON.stringify() method converts a JavaScript value to a JSON string....', parse: 'JSON.parse() method parses a JSON string...',jayson: { stringify: 'JSON.stringify() method converts a JavaScript value to a JSON string....', parse: 'JSON.parse() method parses a JSON string...', jayson: { stringify: 'JSON.stringify() method converts a JavaScript value to a JSON string....', parse: 'JSON.parse() method parses a JSON string...' } } }, } }; var myCopy = null;
Tests:
lodash
myCopy = _.cloneDeep(MyObject);
structuredClone
myCopy = structuredClone(MyObject);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
lodash
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):
Let's break down the provided benchmark definition and explain what is being tested, compared, and considered. **What is being tested?** The benchmark tests two JavaScript methods for creating deep copies of objects: `cloneDeep` from Lodash and `structuredClone`. The test creates an object `MyObject` with multiple levels of nested properties and then attempts to create a copy of it using each of the two methods. **Options compared:** Two options are being compared: 1. **Lodash's `cloneDeep`**: This method is part of the Lodash library, which provides a utility function for creating deep copies of objects. 2. **structuredClone**: This is a built-in JavaScript method introduced in ECMAScript 2020 (ES2020) as a way to create a shallow copy of an object while preserving its structure and values. **Pros and cons:** Here's a brief summary of the pros and cons of each approach: 1. **Lodash's `cloneDeep`**: * Pros: + Supports deep copying, including nested objects and arrays. + Provides additional features like detecting circular references. * Cons: + Adds an external dependency (Lodash library). + Can be slower due to the overhead of calling a separate function. 2. **structuredClone**: * Pros: + Is a built-in JavaScript method, eliminating the need for an external library. + Typically faster since it doesn't involve an extra function call. * Cons: + Only supports shallow copying; to create deep copies, additional steps are required (e.g., using `JSON.parse()` and `JSON.stringify()`). + May not preserve all properties or values, especially if they are not serializable. **Library: Lodash** Lodash is a popular JavaScript utility library that provides a wide range of functions for tasks such as data manipulation, string manipulation, and more. In this case, `cloneDeep` is part of the Lodash library's object utilities. **Special JS feature/syntax: None mentioned** No special JavaScript features or syntax are being tested in this benchmark. **Other alternatives** If you're interested in exploring alternative approaches to deep copying objects, here are a few options: 1. **JSON.parse()` and `JSON.stringify()**: You can use these methods to create a shallow copy of an object by parsing the original object into a JSON string and then reconstructing it from that string. 2. **Array.prototype.slice()` and `Object.assign()`: These methods can be used to create a shallow copy of objects, but they may not work as expected for deeply nested objects. Keep in mind that these alternatives might not provide the same level of functionality or performance as Lodash's `cloneDeep` or structuredClone.
Related benchmarks:
Lodash cloneDeep vs structuredClone deep array
Lodash cloneDeep vs structuredClone vs JSON-JSON
Lodash cloneDeep vs structuredClone vs recursiveDeepCopy vs JSON clone with a more deep test
Lodash cloneDeep vs structuredClone 2asdasdas
Comments
Confirm delete:
Do you really want to delete benchmark?