Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Object cloning with Lodash clone vs cloneDeep vs merge vs ES6 object spread vs ES6 Object.assign BIG
(version: 0)
Comparing performance of:
Lodash clone vs Lodash cloneDeep vs Lodash merge vs ES6 spread vs ES6 Object.assign
Created:
6 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].fill('x', 2, 2000), l: [4,5,6].fill(0, 2, 4000) }, }, e: [1,2,3,4,5,6], f: 1, g: { h: 1, } }
Tests:
Lodash clone
const a = _.clone(o)
Lodash cloneDeep
const a = _.cloneDeep(o)
Lodash merge
const a = _.merge({}, o)
ES6 spread
const a = { ...o }
ES6 Object.assign
const a = Object.assign({}, o)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (5)
Previous results
Fork
Test case name
Result
Lodash clone
Lodash cloneDeep
Lodash merge
ES6 spread
ES6 Object.assign
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 what is being tested in the provided JSON. **Benchmark Definition** The benchmark tests the performance of different approaches to create a shallow copy of an object. There are five test cases: 1. **Lodash clone**: Uses the `_.clone()` function from the Lodash library to create a copy of the original object. 2. **Lodash cloneDeep**: Uses the `_.cloneDeep()` function from the Lodash library to create a deep copy of the original object. 3. **Lodash merge**: Uses the `_.merge()` function from the Lodash library to merge the original object with an empty object, effectively creating a shallow copy. 4. **ES6 spread**: Uses the syntax `{ ...o }` to create a new object with all properties from the original object `o`. 5. **ES6 Object.assign**: Uses the `Object.assign()` function to create a new object with all properties from the original object `o`. **Options Compared** The benchmark compares the performance of these five approaches: * **Lodash clone** and **Lodash cloneDeep**: These two functions use different techniques to create copies of objects. Lodash's `clone` function performs a shallow copy, while `cloneDeep` performs a deep copy. * **Lodash merge** and **ES6 spread**: Both of these approaches create a new object with all properties from the original object, but they do so in different ways. `merge` uses the `_.merge()` function from Lodash, which recursively merges objects, while `spread` uses the syntax `{ ...o }`, which creates a new object by spreading the properties of `o`. * **ES6 Object.assign**: This approach also creates a new object with all properties from the original object. **Pros and Cons** Here are some pros and cons of each approach: 1. **Lodash clone**: * Pros: Simple to use, fast. * Cons: Only performs a shallow copy. 2. **Lodash cloneDeep**: * Pros: Performs a deep copy, useful for complex objects. * Cons: Slower than `clone`. 3. **Lodash merge**: * Pros: Recursively merges objects, can handle nested properties. * Cons: Slower than spread or Object.assign. 4. **ES6 spread**: * Pros: Simple to use, fast. * Cons: Only performs a shallow copy. 5. **ES6 Object.assign**: * Pros: Fast, easy to use. * Cons: Does not perform a deep copy. **Library Usage** The benchmark uses the Lodash library for the `clone`, `cloneDeep`, and `merge` functions. The `Object.assign()` function is a built-in JavaScript function that does not require any external libraries. **Special JS Features/Syntax** There are no special JavaScript features or syntax used in this benchmark, aside from the ES6 spread syntax `{ ...o }`.
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 ES6 object spread vs ES6 Object.assign vs Json
Object cloning with Lodash clone vs cloneDeep vs merge vs ES6 object spread vs ES6 Object.assign vs Clone
Object cloning with Lodash clone vs cloneDeep vs merge vs ES6 object spread vs ES6 Object.assign vs structuredClone
Comments
Confirm delete:
Do you really want to delete benchmark?