Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
merge fn vs deepmerge
(version: 0)
Comparing performance of:
merge vs object.assign
Created:
6 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script>const merge = (target, source) => { // Iterate through `source` properties and if an `Object` set property to merge of `target` and `source` properties for (const key of Object.keys(source)) { if (source[key] instanceof Object) Object.assign(source[key], merge(target[key], source[key])) } // Join `target` and modified `source` Object.assign(target || {}, source) return target }</script> <script src='https://unpkg.com/deepmerge@3.2.0/dist/umd.js'></script>
Tests:
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);
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 = deepmerge({}, a, b);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
merge
object.assign
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll break down the provided benchmark and explain what's being tested, compared, and their pros and cons. **What's being tested?** Two JavaScript functions are being compared: 1. `merge` function (defined in the Script Preparation Code) 2. `deepmerge` library (imported from a CDN) The tests focus on creating deep merges of objects using these two approaches. Specifically, they're comparing the performance of merging two nested object graphs. **What options are compared?** Two options are being compared: 1. **Custom merge function**: The `merge` function defined in the Script Preparation Code. This function iterates through properties, checking if they're objects and recursively merging them. 2. **Deepmerge library**: A third-party library (`deepmerge`) that provides a more efficient and optimized way to perform deep merges. **Pros and Cons:** 1. **Custom merge function**: * Pros: + No external dependencies (only JavaScript) + Simple and straightforward implementation * Cons: + May be slower due to the recursive iteration + Can be less efficient for large object graphs 2. **Deepmerge library**: * Pros: + Optimized for performance, using advanced algorithms and caching + Handles complex merge scenarios with ease * Cons: + External dependency (requires a CDN import) + May add overhead due to the library's abstraction layer **Library: Deepmerge** The `deepmerge` library is designed to provide a fast, efficient, and flexible way to perform deep merges of objects. It uses advanced algorithms and caching techniques to optimize performance. In this benchmark, `deepmerge` is used to merge two nested object graphs using its `deepMerge()` function. The test case provides the input objects (`a` and `b`) and expects the output to be a merged object (`c`). **Special JS feature or syntax** There are no special JavaScript features or syntaxes being tested in this benchmark. **Other alternatives** If you're interested in exploring alternative merge functions, here are a few options: 1. **lodash.merge()**: A popular utility library that provides a `merge()` function for deep merging objects. 2. **immer.merge()`: An immutable merge function from the Immer library, which ensures that merged objects are updated in place. 3. **Object.assign()**: A built-in JavaScript method for assigning properties of one object to another. Keep in mind that these alternatives may have different performance characteristics and use cases compared to the `merge` function defined in the Script Preparation Code or the `deepmerge` library.
Related benchmarks:
lodash merge 4.17.21 vs deepmerge 4.2.2
lodash merge vs deepmerge latest CDN
lodash merge vs deepmerge vs Object.assign
lodash merge vs deepmerge ( 14.17.15 - 4.3.0 )
Comments
Confirm delete:
Do you really want to delete benchmark?