Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash cloneDeep vs structuredClone with map and hashset
(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...' } }; const kitchenSink = { set: new Set([1, 3, 3]), map: new Map([[1, 2]]), regex: /foo/, error: new Error('Hello!') } MyObject.kitchen = kitchenSink; 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 break down the benchmark and explain what is being tested. **Benchmark Definition** The test measures the performance of two approaches to create a deep copy of an object: `lodash.cloneDeep` and the native `structuredClone` function. **Options Compared** Two options are compared: 1. **Lodash cloneDeep**: A popular JavaScript library that provides various utility functions, including `cloneDeep`, which creates a deep copy of an object. 2. **Native structuredClone**: The native implementation of the `structuredClone` function in modern browsers and Node.js environments. **Pros and Cons** Here's a brief overview of each approach: * **Lodash cloneDeep**: + Pros: Well-maintained, widely used, and actively maintained library with a large community. + Cons: Adds an extra dependency to the project, and its performance might not be optimized for all use cases. * **Native structuredClone**: + Pros: Built-in implementation, no additional dependencies required, and potentially faster execution due to native optimization. + Cons: Might not work in older browsers or environments that don't support `structuredClone`, and its performance can vary depending on the specific use case. **Library and Its Purpose** The `lodash` library is a popular JavaScript utility library that provides various functions for tasks like array manipulation, object manipulation, and more. The `cloneDeep` function is specifically designed to create deep copies of objects, which can be useful in scenarios where you need to modify a copy of an original object without affecting the original. **Special JS Feature or Syntax** The test uses the `structuredClone` function, which was introduced in ECMAScript 2022 (ES12). This function creates a deep clone of an object, including its properties and their values. It's designed to work with a wide range of data types, including arrays, objects, and more. **Other Considerations** When choosing between `cloneDeep` and `structuredClone`, consider the following: * If you need to support older browsers or environments that don't support `structuredClone`, use `cloneDeep`. * If performance is critical, and you're using a modern browser or Node.js environment, `structuredClone` might be a better choice. * Always test your code in different environments to ensure it works as expected. **Alternatives** If `structuredClone` is not available or not suitable for your use case, you can consider alternative deep cloning libraries like: * `immer`: A popular library for creating immutable objects that supports deep copying. * `lodash.clone`: Another option from the Lodash family that creates a shallow copy of an object.
Related benchmarks:
Lodash 2.2.0 cloneDeep vs JSON Clone w/ large nested object
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 vs JSON Parse (100 000 objects)
Comments
Confirm delete:
Do you really want to delete benchmark?