Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Dexla - Lodash Merge
(version: 0)
Comparing performance of:
Native vs Lodash merge
Created:
one year ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js"></script>
Tests:
Native
const deepMergeObjects = (...objects) => { const deepCopyObjects = objects.map(object => JSON.parse(JSON.stringify(object))); return deepCopyObjects.reduce((merged, current) => ({ ...merged, ...current }), {}); } var a = { a: 'oh', b: 'my' }; var b = { c: 'goddess' }; var c = deepMergeObjects(a, b);
Lodash merge
var a = { a: 'oh', b: 'my' }; var b = { c: 'goddess' }; var c = _.merge(a, b);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Native
Lodash merge
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/124.0.0.0 Safari/537.36
Browser/OS:
Chrome 124 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Native
1325706.6 Ops/sec
Lodash merge
6732208.5 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. **Benchmark Overview** The benchmark compares two approaches to merge objects in JavaScript: 1. **Native**: This approach uses the built-in `Object.assign()` method to merge objects. 2. **Lodash merge**: This approach uses the `_merge` function from the Lodash library, which is a utility library for functional programming in JavaScript. **Options Compared** The benchmark compares two options: * `Native`: Merging objects using the built-in `Object.assign()` method. * `Lodash merge`: Merging objects using the `_merge` function from the Lodash library. **Pros and Cons of Each Approach** **Native (Object.assign())** Pros: * No external dependency required, as it's a built-in JavaScript method. * Generally faster and more efficient than external libraries. Cons: * May not work correctly with complex object structures or nested objects. * Can be slower for very large objects due to the overhead of creating new objects. **Lodash merge** Pros: * Provides robust support for complex object structures, including nested objects. * Often faster than native `Object.assign()` for very large objects. Cons: * Requires an external dependency on the Lodash library. * May have a slight performance overhead due to the need to load and initialize the library. **Library: Lodash** Lodash is a popular utility library for functional programming in JavaScript. Its `_merge` function provides a convenient way to merge objects, handling complex cases such as nested objects, arrays, and more. The `_merge` function takes two or more objects as input and returns a new object that contains all the key-value pairs from each of the original objects. It also handles cases where keys are common across multiple objects, merging values accordingly. **Other Considerations** * **JavaScript version**: The benchmark may be specific to a particular JavaScript version (e.g., ES5 or ES6). If you're targeting an older JavaScript version, you may need to use a different approach. * **Object size and complexity**: The benchmark may not accurately represent the performance of merging objects with extremely large or complex data sets. In such cases, other factors like memory allocation, garbage collection, and caching may become more significant. **Alternatives** If you don't want to rely on Lodash or built-in JavaScript methods, there are alternative approaches: * **`Object.assign()` with `Array.prototype.concat()`**: This approach can be used for merging arrays as well. * **`Array.prototype.reduce()`**: You can implement your own merge function using `Array.prototype.reduce()`. * **Other libraries**: There are other utility libraries available that provide similar merge functions, such as Underscore.js or FastJSON. Keep in mind that each of these alternatives has its own trade-offs and may not perform as well as Lodash's `_merge` function or built-in JavaScript methods.
Related benchmarks:
Includes Test
isEmpty vs. vanilla
lodash merge vs object.assign vs spread (v2)
lodash merge vs object.assign vs spread (v3)
lodash vs radash 3
Comments
Confirm delete:
Do you really want to delete benchmark?