Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash merge vs object.assign vs spread with access after and control
(version: 0)
Comparing performance of:
lodash merge vs object.assign vs spread vs control
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)
control
var c = {a: 'oh', b: 'my' ,c: 'goddess' } console.log(c)
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
control
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
333967.1 Ops/sec
object.assign
352166.0 Ops/sec
spread
368946.1 Ops/sec
control
378170.2 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what's being tested, compared, and their pros and cons. **Benchmark Overview** The benchmark compares the performance of three JavaScript methods for merging two objects: 1. `lodash.merge` 2. `Object.assign` 3. Spread operator (`...`) Each test case has a unique implementation, and the results are reported in terms of executions per second (ExecutionsPerSecond) on a specific browser and device. **Test Case Breakdown** Here's a brief explanation of each test case: 1. **lodash merge**: Uses the `_.merge()` function from Lodash to merge two objects. 2. **Object.assign**: Uses the `Object.assign()` method to merge two objects. 3. **Spread operator (`...`)**: Uses the spread operator to create a new object with merged properties from two objects. 4. **Control**: A simple test case that logs an existing object without any merging. **Comparison** The benchmark compares the performance of these three methods in terms of executions per second (ExecutionsPerSecond). The results indicate which method is faster under specific conditions. **Pros and Cons of each approach:** 1. **_lodash.merge**: * Pros: Efficiently merges objects, handles complex data structures well. * Cons: Requires an external library (Lodash), may have higher overhead due to the additional dependency. 2. **Object.assign**: * Pros: Part of the standard JavaScript library, easy to use and understand. * Cons: Can be slower than other methods for large objects, might not handle complex data structures well. 3. **Spread operator (`...`)**: * Pros: Simple, efficient, and widely supported (modern browsers and Node.js). * Cons: Limited support for older browsers or environments, might not work as expected with certain data types. **Library usage** The `lodash.merge()` function is used in the first test case. Lodash is a popular JavaScript library that provides utility functions for tasks like array manipulation, object merging, and more. **Special JS feature/Syntax** There are no special features or syntaxes being tested in this benchmark. The focus is on comparing the performance of three standard JavaScript methods. **Other alternatives** If you're interested in exploring alternative methods for merging objects, some other options include: 1. `Object.create()`: Creates a new object with properties inherited from an existing object. 2. `for...in` loop: Iterates over object properties and merges them manually. 3. Custom-built merge functions using recursion or iteration. Keep in mind that these alternatives might have their own trade-offs in terms of performance, readability, and maintainability.
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?