Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash cloneDeep vs structuredClone with array values
(version: 0)
https://developer.mozilla.org/en-US/docs/Web/API/structuredClone
Comparing performance of:
Lodash cloneDeep vs Native 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...' }, arrayOfValues: [ 'asdf', 123, { bob: 's your uncle', nestedArray: [123, 333, { prop: 123 }, ] }, ] }; var myCopy = null;
Tests:
Lodash cloneDeep
myCopy = _.cloneDeep(MyObject);
Native 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 cloneDeep
Native 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 dive into the benchmark. **What is tested?** The provided JSON represents a JavaScript microbenchmark that compares the performance of two approaches for creating a deep copy of an object: 1. `_.cloneDeep` from Lodash 2. The native `structuredClone` API (available in modern browsers) **Options compared:** The benchmark tests two options: * **Lodash cloneDeep**: A popular JavaScript library function that creates a deep copy of an object. * **Native structuredClone**: A new API introduced in modern browsers, which allows creating a deep copy of an object. **Pros and Cons:** 1. **Lodash cloneDeep**: * Pros: + Wide adoption and familiarity among developers + Supports a wide range of data types (arrays, objects, etc.) + Can be easily used in existing codebases * Cons: + Adds an extra dependency to the project (Lodash) + May have additional overhead due to library functions 2. **Native structuredClone**: * Pros: + Built-in API, no extra dependency required + Optimized for performance by browsers + Growing adoption as modern browsers support it * Cons: + Less familiar among developers (not widely adopted yet) + May not work in older browsers or environments **Library and Purpose:** The `structuredClone` API is a new, built-in JavaScript function introduced in ECMAScript 2020. Its purpose is to create a deep copy of an object, which can be useful for tasks like: * Clone and mutate an object without affecting the original * Use objects as cache keys or identifiers * Clone complex data structures (arrays, objects, etc.) **Special JS feature or syntax:** There are no special features or syntaxes used in this benchmark. The focus is on comparing two existing APIs for creating a deep copy. **Other alternatives:** If `structuredClone` is not supported by your browser or environment, you can consider alternative approaches: * **JSON.parse() + JSON.stringify()**: Create an object from a string representation of the original data and then parse it back to create a copy. (Performance-intensive) * **for...of loop with Object.assign()**: Use a `for...of` loop to iterate over the properties of the original object and assign each property value to a new object using `Object.assign()`. (Less efficient than `structuredClone`) * **lodash.cloneDeep() alternative approaches**: If you want to avoid Lodash, you can explore other library functions like `JSON.parse()` + `JSON.stringify()` or implement your own deep copy function. Keep in mind that these alternatives may not be as efficient or reliable as the native `structuredClone` API.
Related benchmarks:
Object Clone Lodash vs structuredClone
Lodash cloneDeep vs structuredClone vs JSON.stringify (small object)
Lodash cloneDeep vs structuredClone vs JSON.stringify with array values
Lodash cloneDeep vs structuredClone vs JSON-JSON
Comments
Confirm delete:
Do you really want to delete benchmark?