Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash clone VS spread operator v4.17.21
(version: 0)
Comparing performance of:
Lodash clone vs Spread operator
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.21/lodash.min.js'></script>
Script Preparation code:
var MyObject = { description: 'a', myNumber: 123456789, myBoolean: true, }; var myCopy = null;
Tests:
Lodash clone
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 clone
Spread operator
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Browser/OS:
Chrome 120 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash clone
1314737.6 Ops/sec
Spread operator
5269673.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided JSON and explain what's being tested. **Benchmark Definition** The benchmark is comparing two approaches to create a copy of an object: using Lodash's `clone()` method (`_.clone(MyObject)`) versus the spread operator (`{...MyObject}`). **Options Compared** 1. **Lodash Clone**: The first option uses Lodash, a popular JavaScript utility library, to clone the object. Lodash provides various functions for common tasks, including data manipulation and iteration. 2. **Spread Operator**: The second option uses the spread operator (`{...MyObject}`), which is a built-in feature in modern JavaScript that allows creating new objects by copying properties from an existing object. **Pros and Cons of Each Approach** 1. **Lodash Clone** * Pros: + More flexible and customizable, as Lodash provides various options for cloning (e.g., `_.cloneDeep()`, `_.cloneWith()`) + Supports complex data structures like arrays and objects * Cons: + Requires an external library, which may add overhead + May not be as performant as the built-in spread operator 2. **Spread Operator** * Pros: + Built-in feature, so no additional library is required + Fast and efficient * Cons: + Only supports shallow copying of properties (i.e., doesn't copy nested objects or arrays) + May not be as flexible as Lodash's cloning methods **Other Considerations** 1. **Lodash Library**: As mentioned earlier, Lodash is a popular utility library that provides various functions for common tasks. In this benchmark, the `clone()` method is used to create a deep copy of the object. 2. **JavaScript Features**: This benchmark does not use any special JavaScript features or syntax beyond the spread operator. **Other Alternatives** 1. **JSON.parse(JSON.stringify())**: Another way to create a shallow copy of an object in JavaScript, but this approach also requires the `JSON` library and may be slower than the built-in spread operator. 2. **Object.assign()**: A method for merging properties from one or more source objects into a target object. While not exactly creating a copy, it can be used to create a new object with merged properties. In summary, this benchmark compares two approaches to create a copy of an object: using Lodash's `clone()` method and the spread operator. The spread operator is a built-in feature that provides fast and efficient shallow copying, while Lodash's cloning methods offer more flexibility and customization options at the cost of additional library overhead.
Related benchmarks:
Lodash cloneDeep VS spread operator
Lodash cloneDeep VS spread operator VS Lodash clone
Lodash clone VS Lodash cloneDeep VS Spread operator with array of objects
Spread Operator vs Lodash (v4.17.21)
Lodash clone VS spread operator shallow
Comments
Confirm delete:
Do you really want to delete benchmark?