Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash merge vs deepmerge (updated FIXED)
(version: 0)
Comparing performance of:
lodash merge vs deepmerge
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.15/lodash.min.js'></script> <script src='https://cdn.jsdelivr.net/npm/deepmerge@4.2.2/dist/cjs.min.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
const combineMerge = (target, source, options) => { const destination = target.slice() source.forEach((item, index) => { if (typeof destination[index] === 'undefined') { destination[index] = options.cloneUnlessOtherwiseSpecified(item, options) } else if (options.isMergeableObject(item)) { destination[index] = merge(target[index], item, options) } else if (target.indexOf(item) === -1) { destination.push(item) } }) return destination } 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, { arrayMerge: combineMerge });
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
lodash merge
deepmerge
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36
Browser/OS:
Chrome 135 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
lodash merge
541750.8 Ops/sec
deepmerge
280756.6 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll provide an explanation of the benchmark, its options, pros and cons, and other considerations. **Benchmark Overview** The provided JSON represents a JavaScript microbenchmark test case for measuring the performance difference between two library functions: `lodash.merge` and `deepmerge`. The test cases aim to compare how quickly each function merges two objects with nested properties. **Test Cases** There are two test cases: 1. **Lodash Merge**: This test case uses the `_merge` function from the Lodash library, which recursively combines two objects. 2. **DeepMerge**: This test case uses a custom implementation of `deepmerge`, which is a variant of the original deep merge algorithm modified to work with array merging. **Options Compared** The options being compared are: * **Lodash Merge**: The `lodash.merge` function has no additional configuration options, whereas the custom implementation in the DeepMerge test case allows for customization through an object passed as an argument (`{ ... }`). + Pros: Lodash provides a well-maintained and widely used library with performance guarantees. + Cons: Custom implementation may not be optimized or tested extensively, potentially leading to slower performance compared to the original Lodash implementation. * **DeepMerge**: The custom `deepmerge` function uses an array merging strategy (`combineMerge`) that is more efficient for large objects with nested arrays. + Pros: Custom implementation can provide better performance for specific use cases, such as array merging. + Cons: Requires additional configuration and maintenance effort. **Library Overview** * **Lodash**: Lodash is a popular JavaScript utility library providing functions for tasks like string manipulation, object manipulation, and more. In this benchmark, `_merge` is used to recursively combine two objects. * **DeepMerge**: DeepMerge is a lightweight library designed specifically for deeply merging two objects with nested properties. **Special JS Feature or Syntax** Neither of the libraries relies on special JavaScript features or syntax that would impact performance significantly. The focus is on optimizing object merge operations, which are a common use case in many applications. **Other Alternatives** Some alternative approaches to deep merging include: * Using the `Object.assign()` method for shallow merges. * Implementing a custom recursive function for deep merging. * Using a dedicated library like Immutable.js for functional programming and immutable data structures. * Leveraging modern JavaScript features, such as ES6 classes or Object destructuring, for simpler merge operations. Keep in mind that the choice of approach depends on the specific use case requirements, performance constraints, and personal preference.
Related benchmarks:
lodash merge vs deepmerge (updated)
lodash merge vs deepmerge 4.2.2
lodash merge vs deepmerge 4.2.2 vs own merge implementation
lodash vs deepmerge vs deepmerge-ts vs ts-deepmerge
Comments
Confirm delete:
Do you really want to delete benchmark?