Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash clone VS spread operator
(version: 0)
Comparing performance of:
Lodash cloneDeep vs Spread operator
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: 'a', myNumber: 123456789, myBoolean: true, }; var myCopy = null;
Tests:
Lodash cloneDeep
myCopy = _.clone(MyObject);
Spread operator
myCopy = {...MyObject};
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Lodash cloneDeep
Spread operator
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
7 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36 OPR/120.0.0.0 (Edition Yx 08)
Browser/OS:
Opera 120 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash cloneDeep
5107566.5 Ops/sec
Spread operator
16772802.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and explain what's being tested, compared, and their pros and cons. **Benchmark Overview** The benchmark measures the performance of two approaches to create a copy of an object: 1. **Lodash cloneDeep**: Using the `_.cloneDeep()` function from the Lodash library. 2. **Spread operator**: Using the spread operator (`...`) to create a new object by spreading the properties of the original object. **Lodash Library** The Lodash library is a popular utility library for JavaScript that provides a wide range of functions for tasks such as array manipulation, object manipulation, and more. In this benchmark, `_.cloneDeep()` is used to create a deep copy of an object. **Spread Operator** The spread operator (`...`) is a new feature introduced in ECMAScript 2018 (ES8). It allows you to create a new object by spreading the properties of an existing object. **Test Cases and Results** The benchmark compares the performance of `_.cloneDeep()` and the spread operator for creating a copy of a small object (`MyObject`). The test cases are: 1. **Lodash cloneDeep**: Creates a deep copy of `MyObject` using Lodash's `_.cloneDeep()`. 2. **Spread operator**: Creates a new object by spreading the properties of `MyObject`. The latest benchmark result shows that the spread operator outperforms `_.cloneDeep()` in terms of executions per second: * Spread operator: 6033532.5 executions/second * Lodash cloneDeep: 1740839.875 executions/second **Pros and Cons** **Lodash CloneDeep** Pros: * Provides a safe and efficient way to create deep copies of objects. * Handles complex object graphs with ease. Cons: * Adds an extra dependency on the Lodash library. * May have additional overhead due to the size of the library. **Spread Operator** Pros: * Lightweight and doesn't add any dependencies. * Fast and efficient for small objects. Cons: * Only works for simple objects and may not handle complex object graphs. * May lead to unexpected behavior if not used carefully (e.g., modifying the original object). **Other Alternatives** If you don't want to use Lodash or the spread operator, other alternatives include: * Using the `Object.assign()` method with the spread operator (`Object.assign({}, ...MyObject)`) * Implementing a custom copying function that recursively clones objects * Using a different library like Immutable.js (although this would add an extra dependency) **Special JS Feature/Syntax** Note that this benchmark does not rely on any special JavaScript features or syntax, so it should be accessible to most developers.
Related benchmarks:
Lodash cloneDeep VS spread operator
Lodash cloneDeep vs clone vs spread
Lodash cloneDeep VS spread operator VS Lodash clone
Lodash clone VS Lodash cloneDeep VS Spread operator with array of objects
Lodash clone VS spread operator shallow
Comments
Confirm delete:
Do you really want to delete benchmark?