Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash merge vs object.assign vs spread new obj
(version: 0)
Comparing performance of:
lodash merge vs 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>
Script Preparation code:
var a = { a: 'oh', b: 'my' }; var b = { c: 'goddess', d: 'a', e: 'b', j: { asd: 'test' } };
Tests:
lodash merge
var c = _.merge({}, a, b);
object.assign
var c = Object.assign({}, a, b);
spread
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 merge
object.assign
spread
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
6 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36
Browser/OS:
Chrome 141 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
lodash merge
1621368.4 Ops/sec
object.assign
13696075.0 Ops/sec
spread
13889735.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Benchmark Explanation** The provided JSON represents a benchmarking test created on MeasureThat.net, which compares the performance of three approaches for merging two objects: Lodash's `merge` function, `Object.assign`, and spread operator (`...`). The goal is to determine which method is the most efficient. **Options Compared** 1. **Lodash's `merge` function**: This approach uses a library (Lodash) to merge the two objects. 2. **`Object.assign`**: This approach uses a built-in JavaScript method to merge the two objects. 3. **Spread operator (`...`)**: This approach uses a new feature in modern JavaScript to create a new object by spreading the properties of two existing objects. **Pros and Cons** 1. **Lodash's `merge` function**: * Pros: Well-tested, widely used library; provides a flexible way to merge objects with custom logic. * Cons: Requires including an additional library, which may increase load times. 2. **`Object.assign`**: * Pros: Built-in method; fast and lightweight. * Cons: Only available in modern browsers (ECMAScript 2015+); may not work in older browsers. 3. **Spread operator (`...`)**: * Pros: Modern JavaScript feature; concise syntax; no additional libraries required. * Cons: May not be supported in older browsers or environments; requires ES6+ support. **Library and Syntax** The benchmark uses Lodash's `merge` function, which is a utility library for functional programming. The spread operator (`...`) is a new feature introduced in ECMAScript 2015 (ES6). **Benchmark Preparation Code** The provided script preparation code sets up two objects, `a` and `b`, to be merged: ```javascript var a = { a: 'oh', b: 'my' }; var b = { c: 'goddess', d: 'a', e: 'b', j: { asd: 'test' } }; ``` **Other Alternatives** If you're interested in exploring alternative approaches, here are some options: 1. **JSON merge libraries**: Other libraries like `jsonmerge` or `deepmerge` can be used instead of Lodash's `merge`. 2. **Other built-in methods**: The `reduce()` method or a custom loop could be used to merge objects. 3. **Template literals**: A newer feature, template literals (``${...}``) could be used to concatenate object properties. Keep in mind that the performance differences between these approaches may vary depending on your specific use case and environment.
Related benchmarks:
lodash.assign vs object.assign vs spread
lodash merge vs object.assign vs spread (no intermediate vars)
lodash assign vs object.assign vs spread operator - variable and constant
lodash merge vs object.assign vs spread with empty receiving object
Comments
Confirm delete:
Do you really want to delete benchmark?