Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash merge vs object.assign vs spread with access after
(version: 0)
Comparing performance of:
lodash merge vs object.assign vs spread
Created:
one year 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 merge
var a = { a: 'oh', b: 'my' }; var b = { c: 'goddess' }; var c = _.merge(a, b); console.log(c)
object.assign
var a = { a: 'oh', b: 'my' }; var b = { c: 'goddess' }; var c = Object.assign(a, b); console.log(c)
spread
var a = { a: 'oh', b: 'my' }; var b = { c: 'goddess' }; var c = { ...a, ...b }; console.log(c)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
lodash merge
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/131.0.0.0 Safari/537.36
Browser/OS:
Chrome 131 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
lodash merge
342070.8 Ops/sec
object.assign
369766.1 Ops/sec
spread
366794.9 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the explanation of the provided benchmark. **What is being tested?** The benchmark is comparing three approaches to merge two objects in JavaScript: 1. `_.merge` from Lodash library 2. `Object.assign` 3. Spread operator (`{ ...a, ...b }`) Each approach is being tested with a sample code snippet that creates two objects and merges them. **Options comparison** The three options are compared based on their execution time. The goal of the benchmark is to determine which approach is the fastest in terms of performance. **Pros and Cons:** 1. **_.merge (Lodash)**: * Pros: `_.merge` is a well-tested and widely used function, it can handle nested objects, and it's often considered the most readable and maintainable option. * Cons: It requires an external library (Lodash), which might increase overhead due to dependencies and module loading. 2. **Object.assign**: * Pros: `Object.assign` is a built-in JavaScript method, making it fast and lightweight. It also works well with nested objects. * Cons: It can be less readable than other options, especially when dealing with complex object structures. 3. **Spread operator (`{ ...a, ...b }`)**: * Pros: The spread operator is a concise and modern way to merge objects. It's also relatively fast and efficient. * Cons: It might not work well with nested objects or complex data structures. **Library usage** The `_.merge` function from Lodash library is being used as part of the benchmark. Lodash is a popular utility library for JavaScript that provides various functions to simplify common tasks, such as array manipulation, string templating, and object merging. **Special JS feature/syntax** There are no special JavaScript features or syntax being tested in this benchmark. The code snippets only use standard JavaScript syntax and built-in methods (e.g., `Object.assign`). **Alternatives** If you're looking for alternative ways to merge objects in JavaScript without using the spread operator, you could consider: 1. Using a library like Underscore.js or Ramda instead of Lodash. 2. Implementing your own object merging function from scratch. 3. Using a different approach, such as using `Array.prototype.reduce()` or `Object.create()`, to merge objects. Keep in mind that each alternative might have its own pros and cons, and the performance characteristics may vary depending on the specific use case and environment.
Related benchmarks:
lodash merge vs object.assign vs spread new obj
lodash.assign vs object.assign vs spread
lodash merge vs object.assign vs spread overwriting one property
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?