Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash merge vs deepmerge vs Object.assign
(version: 0)
Comparing performance of:
lodash merge vs deepmerge vs object.assign
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> <script src='https://unpkg.com/deepmerge@3.2.0/dist/umd.js'></script>
Tests:
lodash merge
var a = { a: 'oh', b: 'my', c: { a: 'a', b: { c: 'c' } } }; var b = { c: { b: { d: 'a' }, c: { d: 'd' } } }; var c = _.merge({}, a, b);
deepmerge
var a = { a: 'oh', b: 'my', c: { a: 'a', b: { c: 'c' } } }; var b = { c: { b: { d: 'a' }, c: { d: 'd' } } }; var c = deepmerge({}, a, b);
object.assign
var a = { a: 'oh', b: 'my', c: { a: 'a', b: { c: 'c' } } }; var b = { c: { b: { d: 'a' }, c: { d: 'd' } } }; var c = Object.assign({}, a, b);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
lodash merge
deepmerge
object.assign
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
3 days ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Safari/537.36
Browser/OS:
Chrome 147 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
lodash merge
626262.4 Ops/sec
deepmerge
3602062.0 Ops/sec
object.assign
19067384.0 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 the pros and cons of each approach. **Overview** The benchmark is designed to compare the performance of three functions: 1. `Object.assign()` 2. `deepmerge()` 3. `lodash.merge()` These functions are used to merge two objects into one. The test cases use similar input data with slight variations, allowing us to isolate the differences in performance between these libraries. **What's being tested** The benchmark is testing how efficient each library is when merging objects. Specifically, it's measuring: * How many executions per second (executionsPerSecond) for each library * The speed difference between the three libraries **Options compared** 1. **`Object.assign()`**: A built-in JavaScript function that merges two or more source objects into a new object. 2. **`deepmerge()`**: A third-party library that provides a deep merge function, allowing you to merge objects recursively. 3. **`lodash.merge()`**: A utility function from the Lodash library that performs a deep merge of two objects. **Pros and Cons** 1. `Object.assign()`: * Pros: Built-in, easy to use, no dependencies. * Cons: Can lead to shallow merges if not used carefully, performance might be slower than specialized libraries. 2. `deepmerge()`: * Pros: Efficient for deep merges, handles recursive structures well, and is a dedicated library for this purpose. * Cons: Requires additional dependency (the library itself), might have a steeper learning curve due to its specific API. 3. `lodash.merge()`: * Pros: Fast, reliable, and easy to use within the context of Lodash, which provides many other useful utility functions. * Cons: Adds an extra dependency (Lodash) and might not be as efficient as dedicated libraries like `deepmerge()`. **Library explanations** 1. `deepmerge`: A small library created by Andrew Whitehurst that provides a simple and efficient way to merge objects recursively. It's designed for use cases where deep merging is necessary, such as when working with complex data structures. 2. `lodash.merge()`: A part of the Lodash utility library, which includes many functions for common tasks like array manipulation, object creation, and more. The `merge()` function is specifically designed to handle deep merges of objects. **Special JS features or syntax** None are mentioned in this benchmark.
Related benchmarks:
lodash merge vs deepmerge.all
lodash merge vs deepmerge latest CDN
lodash merge vs deepmerge latest
Lodash merge vs deepmerge lksafkmasldsa
Comments
Confirm delete:
Do you really want to delete benchmark?