Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash cloneDeep vs structuredClone fork
(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...' } }; var myCopy = null;
Tests:
Lodash cloneDeep
myCopy = JSON.parse(JSON.stringify(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 provided benchmark and explain what is being tested. **Benchmark Overview** The benchmark compares two approaches to creating a deep copy of an object: using Lodash's `cloneDeep` function and the native `structuredClone` method introduced in ECMAScript 2020. The benchmark creates a test object with nested properties, including a JSON string representation, and then attempts to create a deep copy of it using both methods. **Options Compared** The two options being compared are: 1. **Lodash cloneDeep**: Lodash's `cloneDeep` function is used to create a deep copy of the test object. This method recursively traverses the object graph, creating new objects for each nested property. 2. **Native structuredClone**: The native `structuredClone` method is used to create a deep copy of the test object. This method also recursively traverses the object graph and creates new objects for each nested property. **Pros and Cons** Here are some pros and cons of each approach: * **Lodash cloneDeep**: + Pros: Widely supported, well-tested, and easy to use. + Cons: Adds extra overhead due to Lodash's additional JavaScript code. * **Native structuredClone**: + Pros: Optimized for performance, as it's a built-in method in modern browsers. + Cons: Requires support for ECMAScript 2020, which might not be available in older browsers. **Library and Purpose** The `structuredClone` method is a part of the ECMAScript standard and was introduced in ECMAScript 2020. It provides a fast and efficient way to create deep copies of objects, arrays, and other data structures. The purpose of this method is to provide a high-performance alternative to traditional cloning methods. **Special JS Features or Syntax** The benchmark uses ECMAScript 2020's `structuredClone` method, which introduces a new syntax for creating deep copies: `structuredClone(source)`. This feature requires support for ECMAScript 2020 in the browser. **Other Alternatives** If the browser does not support `structuredClone`, other alternatives can be used to create deep copies: 1. **JSON.parse(JSON.stringify())**: A widely supported method that creates a deep copy by serializing the object to JSON and then parsing it back into an object. 2. **for...in loop**: A manual approach using a for-in loop to iterate over the object's properties and create new objects. In summary, the benchmark compares two approaches to creating deep copies of objects: Lodash's `cloneDeep` function and the native `structuredClone` method introduced in ECMAScript 2020. The choice between these options depends on performance considerations, browser support, and personal preference.
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?