Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
_.merge vs _.assign vs JS reduce
(version: 0)
Comparing performance of:
Lodash merge vs Lodash assign vs Js reduce
Created:
2 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 Preparation code:
var array = Array(1000).fill().map((_, index) => ({ [(Math.random() + 1).toString(36).substring(2)]: index }))
Tests:
Lodash merge
_.merge({}, ...array)
Lodash assign
_.assign({}, ...array)
Js reduce
array.reduce((acc, item) => ({...acc, ...item}), {})
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Lodash merge
Lodash assign
Js reduce
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/133.0.0.0 Safari/537.36 Edg/133.0.0.0
Browser/OS:
Chrome 133 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash merge
1718.7 Ops/sec
Lodash assign
3343.6 Ops/sec
Js reduce
25.9 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into explaining the benchmark. **Overview** The provided JSON represents a JavaScript microbenchmarking test created using MeasureThat.net. The test compares the performance of three approaches: Lodash `merge` and `assign` functions, as well as the native `reduce` method in JavaScript. **Test Cases** There are three individual test cases: 1. **Lodash merge**: This test case measures the performance of Lodash's `merge` function, which merges multiple objects into a single object. 2. **Lodash assign**: Similar to the previous one, this test case measures the performance of Lodash's `assign` function, but it assigns values from an array of objects to a target object. 3. **Js reduce**: This test case uses the native `reduce` method in JavaScript to merge multiple objects into a single object. **Approaches Compared** The three approaches are compared in terms of their execution time on the provided dataset of 1000 objects, each with random properties and values. **Pros and Cons** Here's a brief overview of the pros and cons of each approach: * **Lodash `merge` and `assign`**: These functions provide a convenient and readable way to merge objects. However, they might incur additional overhead due to their implementation complexity. The performance difference between these two functions is relatively small. * **Native `reduce`**: This method provides a lightweight and efficient way to merge objects. It's often used in functional programming and can be more intuitive for developers familiar with it. **Considerations** When choosing an approach, consider the following factors: * Readability: If you prioritize readability, Lodash's `merge` and `assign` functions might be more suitable. * Performance: If performance is critical, the native `reduce` method or a custom implementation using a loop might be a better choice. * Complexity: If you're dealing with complex data structures or need to merge objects recursively, Lodash's `merge` function might be more suitable. **Library and Purpose** The included Lodash library provides several utility functions for JavaScript, including `merge` and `assign`. These functions can simplify common tasks such as merging objects and arrays. **Special JS Feature/Syntax (Not Applicable)** This benchmark does not use any special JavaScript features or syntax that would affect the performance comparison. **Alternatives** If you're looking for alternative approaches to merge objects, here are a few options: * **Using a loop**: You can use a simple loop to iterate over the object properties and assign values. This approach is lightweight but might be less readable than using Lodash's `merge` or native `reduce` methods. * **Using a custom implementation**: You can write a custom function to merge objects, which might provide better performance if you're dealing with complex data structures. Keep in mind that the choice of approach ultimately depends on your specific use case and requirements.
Related benchmarks:
Loop over object: lodash vs Object.entries fork by d9k 2
Unique lodash vs vanilla
test123_123
_.merge vs _.assign vs _.reduce vs JS reduce vs Js assign
Comments
Confirm delete:
Do you really want to delete benchmark?