Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Object cloning with Lodash cloneDeep vs merge vs structuredClone
(version: 0)
Comparing performance of:
Lodash cloneDeep vs Lodash merge vs ES6 structuredClone
Created:
2 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 o = { a: { b: 1, c: 2, d: 3, j: { k: [1,2,3], l: [4,5,6] }, }, e: [1,2,3,4,5,6], f: 1, g: { h: 1, } }
Tests:
Lodash cloneDeep
const a = _.cloneDeep(o)
Lodash merge
const a = _.merge({}, o)
ES6 structuredClone
const a = structuredClone(o)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Lodash cloneDeep
Lodash merge
ES6 structuredClone
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36
Browser/OS:
Chrome 145 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash cloneDeep
559896.0 Ops/sec
Lodash merge
390653.9 Ops/sec
ES6 structuredClone
601643.8 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Overview** The provided benchmark, hosted on MeasureThat.net, compares the performance of three methods for object cloning in JavaScript: Lodash's `cloneDeep`, `merge`, and ES6's `structuredClone`. The test creates a complex JSON object (`o`) and measures how long each method takes to clone it. **Method Comparison** ### 1. Lodash `cloneDeep` * **Description:** `cloneDeep` is a deep cloning function that recursively copies all properties of the original object, including nested objects. * **Pros:** * Accurately clones complex objects with nested structures. * Handles circular references by creating a new graph. * **Cons:** * Can be slower due to its recursive nature and handling of complex data structures. ### 2. Lodash `merge` * **Description:** `merge` is a function that creates a new object with the properties from two or more source objects, merging them into a single object. * **Pros:** * Fast and efficient for simple cloning operations. * Handles primitive values and basic data types. * **Cons:** * Does not handle complex object structures, such as nested arrays or circular references. ### 3. ES6 `structuredClone` * **Description:** `structuredClone` is a new function in ECMAScript 2020 that creates a shallow copy of an object. * **Pros:** * Fast and efficient for simple cloning operations. * Handles primitive values and basic data types. **Library Used: Lodash** Lodash is a popular JavaScript utility library that provides various functions for tasks such as array manipulation, object manipulation, and more. In this benchmark, `cloneDeep` and `merge` are used to compare the performance of deep cloning and simple merging operations. **Special JS Feature or Syntax (None)** There is no special JavaScript feature or syntax used in this benchmark. **Other Alternatives** Other methods for object cloning in JavaScript include: * **Object.assign()**: Creates a new object with the properties from an existing source object. * **JSON.parse(JSON.stringify(o))**: Creates a deep copy of the original object by parsing its JSON representation and recreating it. These alternatives may have different performance characteristics, handling complex data structures, or use different methods to create clones.
Related benchmarks:
Object cloning with Lodash clone vs cloneDeep vs merge vs ES6 object spread vs ES6 Object.assign
Object cloning with Lodash clone vs cloneDeep vs merge vs ES6 object spread vs ES6 Object.assign vs structuredClone
Object cloning with Lodash clone vs cloneDeep vs merge vs structuredClone vs JSON.parse(JSON.stringify(o))
Object cloning with Lodash clone vs cloneDeep vs merge vs structuredClone vs JSON.parse(JSON.stringify(o)) 2
Comments
Confirm delete:
Do you really want to delete benchmark?