Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash cloneDeep vs structuredClone
(version: 0)
https://developer.mozilla.org/en-US/docs/Web/API/structuredClone
Comparing performance of:
Lodash cloneDeep vs Native structuredClone
Created:
4 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...' } }; 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:
Run details:
(Test run date:
15 days ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Safari/537.36
Browser/OS:
Chrome 147 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash cloneDeep
2015792.2 Ops/sec
Native structuredClone
654433.7 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and its components. **Benchmark Definition** The provided JSON represents a JavaScript microbenchmark that compares two approaches for creating deep copies of objects: `Lodash cloneDeep` and `structuredClone`. The benchmark is designed to test the performance of these two methods on a specific set of input data. **Options Compared** Two options are compared: 1. **Lodash cloneDeep**: This method is part of the popular Lodash library, which provides a utility function for creating deep copies of objects. 2. **structuredClone**: This is a native JavaScript method introduced in ECMAScript 2020 (ES2020) that creates a deep copy of an object. **Pros and Cons** Here are some pros and cons of each approach: * **Lodash cloneDeep**: + Pros: widely adopted, well-tested, and widely supported. + Cons: adds an external dependency (the Lodash library), which may not be desirable for all projects. Also, the deep cloning process can be complex and error-prone if not implemented correctly. * **structuredClone**: + Pros: native to JavaScript, no external dependencies, and more efficient than `cloneDeep` in some cases. + Cons: only supported in modern browsers that implement ES2020 or later. Additionally, the method requires careful handling of circular references and other edge cases. **Library (Lodash)** The Lodash library is a popular utility library for JavaScript that provides a wide range of functions for tasks such as array manipulation, object transformation, and more. In this benchmark, `cloneDeep` is used to create deep copies of objects. **Special JS Feature (ECMAScript 2020)** The `structuredClone` method is a new feature introduced in ECMAScript 2020, which allows creating deep copies of objects using the `structuredClone()` function. This method is designed to be more efficient and easier to use than traditional cloning methods like `JSON.parse(JSON.stringify())`. **Other Considerations** When working with complex object graphs, other factors such as memory allocation, garbage collection, and caching can also impact performance. In this benchmark, only the execution speed of each approach is being measured. **Alternatives** If you need to create deep copies of objects in a JavaScript environment without access to ES2020 or later, alternative approaches include: 1. Using `JSON.parse(JSON.stringify(obj))`, which creates a shallow copy of the object. 2. Implementing a custom cloning function using recursion or iteration. 3. Using a library like Lodash (in addition to the built-in `structuredClone` method). Keep in mind that each approach has its trade-offs, and the choice ultimately depends on your specific use case and performance requirements.
Related benchmarks:
Object Clone Lodash vs structuredClone
Lodash cloneDeep vs structuredClone vs JSON.stringify (small object)
Lodash (4.17.11) cloneDeep vs JSON Clone vs structuredClone
Lodash cloneDeep vs structuredClone vs JSON-Clone
Lodash cloneDeep vs structuredClone vs Json.stringify
Comments
Confirm delete:
Do you really want to delete benchmark?