Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash merge vs object.assign vs spread with deep values
(version: 0)
Comparing performance of:
lodash merge vs object.assign vs spread
Created:
4 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 merge
var a = { a: 'oh', b: 'my', deep: {a:'a',b:'b'} }; var b = { c: 'goddess' , deep: {c: 'c', b: 'b2'}}; var c = _.merge(a, b);
object.assign
var a = { a: 'oh', b: 'my', deep: {a:'a',b:'b'} }; var b = { c: 'goddess' , deep: {c: 'c', b: 'b2'}}; var c = Object.assign(a, b, {deep: Object.assign(a.deep, b.deep)});
spread
var a = { a: 'oh', b: 'my', deep: {a:'a',b:'b'} }; var b = { c: 'goddess' , deep: {c: 'c', b: 'b2'}}; var c = { ...a, ...b, deep:{...a.deep, ...b.deep} };
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/136.0.0.0 Safari/537.36
Browser/OS:
Chrome 136 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
lodash merge
4067663.2 Ops/sec
object.assign
22907374.0 Ops/sec
spread
20207396.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Overview** MeasureThat.net is a website that allows users to create and run JavaScript microbenchmarks, comparing different approaches for merging objects with nested properties. **Benchmark Definition JSON** The provided benchmark definition JSON consists of three test cases: 1. `lodash merge`: Tests the performance of Lodash's `merge` function. 2. `object.assign`: Tests the performance of the built-in `Object.assign` method. 3. `spread`: Tests the performance of the spread operator (`...`) for merging objects. **Options Compared** The three options compared are: 1. **Lodash merge**: Uses the `merge` function from Lodash to merge two objects, including nested properties. 2. **Object.assign**: Uses the built-in `Object.assign` method to merge two objects, including nested properties. 3. **Spread operator**: Uses the spread operator (`...`) to merge two objects, including nested properties. **Pros and Cons** Here's a brief summary of the pros and cons of each approach: 1. **Lodash merge**: * Pros: Efficiently handles deep object merges with recursion. * Cons: Requires Lodash to be included in the scope (adds overhead). 2. **Object.assign**: * Pros: Built-in method, efficient for shallow merges. * Cons: Can lead to recursive function calls for deep merges, potentially causing performance issues. 3. **Spread operator**: * Pros: Simple, efficient, and does not require any additional libraries. * Cons: Limited control over merge behavior (e.g., handling nested arrays). **Library and Purpose** The `lodash` library is a popular JavaScript utility library that provides a wide range of functions for manipulating data. In this benchmark, Lodash's `merge` function is used to merge objects with nested properties. **Special JS Feature or Syntax** There is no special feature or syntax mentioned in the benchmark definition. However, it's worth noting that older browsers may not support the spread operator (`...`) or `Object.assign`. **Other Alternatives** If you'd like to explore alternative approaches, here are a few options: 1. **JSON merge**: Uses a custom JSON merge function (not shown in this example) to compare the behavior of different merge libraries. 2. **Iterative merge**: Implements an iterative merge algorithm that uses loops and conditional statements instead of recursion or built-in methods. These alternatives may offer different trade-offs in terms of performance, complexity, and control over the merge behavior.
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?