Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash immutable merge vs object.assign vs spread
(version: 0)
Comparing performance of:
lodash immutable merge vs immutable object.assign vs spread
Created:
7 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>
Tests:
lodash immutable merge
var a = { a: 'oh', b: 'my' }; var b = { c: 'goddess' }; var c = _.merge({}, a, b);
immutable 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 };
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
lodash immutable merge
immutable object.assign
spread
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36
Browser/OS:
Chrome 134 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
lodash immutable merge
9240230.0 Ops/sec
immutable object.assign
37047700.0 Ops/sec
spread
49931128.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Overview of the Benchmark** The provided benchmark, hosted on MeasureThat.net, compares the performance of three approaches for merging two objects: `lodash`'s immutable merge (`_.merge()`), `object.assign()` (including an immutable version), and the spread operator (`{ ...a, ...b }`). The goal is to determine which approach is the fastest. **Options Compared** 1. **Lodash Immutable Merge**: Uses the `_.` function from the Lodash library to perform an immutable merge. 2. **Immutable Object Assign**: Wraps `object.assign()` with a function that returns a new object, ensuring immutability. 3. **Spread Operator**: Utilizes the spread operator (`{ ...a, ...b }`) to create a new object by spreading the properties of two objects. **Pros and Cons of Each Approach** 1. **Lodash Immutable Merge** * Pros: + Provides an immutable result. + Often used for its concise syntax. * Cons: + Requires including Lodash in the project, adding overhead. + May have slower performance due to library dependencies. 2. **Immutable Object Assign** * Pros: + Ensures immutability without relying on external libraries. + Can be faster since it doesn't introduce additional dependencies. * Cons: + The implementation can be more verbose than the spread operator. 3. **Spread Operator** * Pros: + Fast and concise syntax. + Does not require any external libraries or dependencies. * Cons: + May not provide explicit control over the merging process. **Library Used: Lodash** Lodash is a popular JavaScript utility library that provides a wide range of functions for tasks such as array manipulation, object manipulation, and more. The `_.merge()` function is specifically designed to merge two or more objects into one, ensuring immutability by default. **Special JS Feature/Syntax: None** There are no special JavaScript features or syntaxes used in this benchmark beyond the standard language features supported by all browsers. **Other Considerations** When choosing an approach for merging objects, consider the following factors: * **Immutability**: Do you need to ensure that the merged object is immutable? * **Performance**: Are speed and efficiency critical for your use case? * **Code Readability**: How important is code readability and conciseness in your project? **Alternatives** If you're interested in exploring other options, consider: 1. Using `Object.assign()` without the wrapper function to achieve immutability. 2. Implementing a custom merge function using a library like Immutable.js or Ramda. 3. Utilizing other JavaScript libraries or frameworks that provide similar functionality. Keep in mind that each alternative may have its own trade-offs and considerations, so be sure to evaluate them based on your specific needs and requirements.
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?