Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash assign lodash merge vs object.assign vs spread
(version: 0)
Comparing performance of:
lodash merge vs object.assign vs spread vs lodash assign
Created:
7 years ago
by:
Registered User
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>
Tests:
lodash merge
var a = { a: 'oh', b: 'my' }; var b = { c: 'goddess' }; var c = _.merge(a, b);
object.assign
var a = { a: 'oh', b: 'my' }; var b = { c: 'goddess' }; var c = Object.assign(a, b);
spread
var a = { a: 'oh', b: 'my' }; var b = { c: 'goddess' }; var c = { ...a, ...b };
lodash assign
var a = { a: 'oh', b: 'my' }; var b = { c: 'goddess' }; var c = _.assign(a, b);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
lodash merge
object.assign
spread
lodash assign
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36
Browser/OS:
Chrome 123 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
lodash merge
3253564.8 Ops/sec
object.assign
5545124.0 Ops/sec
spread
18868264.0 Ops/sec
lodash assign
3911040.8 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and its test cases. **What is being tested?** The benchmark tests four different ways to merge or assign properties from two objects: Lodash's `merge` function, `assign` function, `object.assign`, and the spread operator (`...`). The objective is to compare their performance in terms of execution speed. **Options compared:** 1. **Lodash `merge`**: A utility function that merges two objects into a new object. 2. **Lodash `assign`**: A utility function that assigns properties from one object to another. 3. **`object.assign`**: A built-in JavaScript method that assigns properties from one object to another. 4. **Spread operator (`...`)**: A feature introduced in ECMAScript 2015, which allows creating a new object by spreading the properties of an existing object. **Pros and Cons:** 1. **Lodash `merge`**: * Pros: Convenient utility function with optional options for merging, less boilerplate code. * Cons: External dependency on Lodash, may introduce overhead due to library loading. 2. **Lodash `assign`**: * Pros: Similar to `merge`, but with a single method that can be used for assignment. * Cons: Also introduces an external dependency on Lodash. 3. **`object.assign`**: * Pros: Built-in JavaScript method, no dependencies or overhead. * Cons: May require creating an empty object as the target, and its behavior is not explicitly stated in older browsers. 4. **Spread operator (`...`)**: * Pros: Concise syntax, well-supported across modern browsers and environments. * Cons: May not work with older browsers that don't support it. **Library used:** Lodash (version 4.17.5) is used as the utility library for `merge` and `assign` functions. Lodash provides a set of higher-order functions, including `merge` and `assign`, which can be useful in many situations. **Special JS feature or syntax:** The spread operator (`...`) is a relatively new JavaScript feature introduced in ECMAScript 2015. It allows creating a new object by spreading the properties of an existing object, making it concise and expressive. **Other alternatives:** In addition to the options mentioned above, there are other ways to merge or assign properties from two objects: * `Object.assign()` with an empty object as the target * Using the `for...in` loop and assigning each property individually * Implementing a custom merge function using recursion However, these alternatives may be less efficient, more verbose, or not supported in older browsers.
Related benchmarks:
lodash merge vs object.assign vs spread new obj
lodash.assign vs object.assign vs spread
Array Properties Merge: Lodash merge vs Object.assign
lodash merge vs object.assign vs spread (no intermediate vars)
lodash assign vs object.assign vs spread operator - variable and constant
Comments
Confirm delete:
Do you really want to delete benchmark?