Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash groupBy vs Array.reduce 100k with array push
(version: 0)
Comparing performance of:
Lodash vs Native
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 max2 = 100000; var data = []; for (var i = 0; i <= max2; i++) { data.push({ id: i }); }
Tests:
Lodash
_.groupBy(data, ({ id }) => id)
Native
data.reduce((acc, item) => { if (acc[item.id]) { acc[item.id].push(item) } else { acc[item.id] = [item]; } return acc; }, {})
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Lodash
Native
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
5 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36
Browser/OS:
Chrome 142 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash
395.5 Ops/sec
Native
912.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and its components. **What is being tested?** MeasureThat.net is testing the performance difference between two approaches for grouping an array of objects based on a specific property: 1. Using the `groupBy` function from the Lodash library, which groups an array by a specified function. 2. Implementing the grouping logic using the native `Array.reduce()` method. **Options compared** The benchmark is comparing the performance of these two approaches: * **Lodash**: The `groupBy` function from Lodash is used to group the data. Lodash is a utility library that provides a set of high-order functions for functional programming. * **Native**: The grouping logic is implemented using the native `Array.reduce()` method, which applies a function against an accumulator and a series of values in the array. **Pros and cons** Here are some pros and cons of each approach: **Lodash (`groupBy`):** Pros: * More concise and readable code * Less error-prone, as it's a well-tested library with a clear API * Can handle complex grouping logic Cons: * Adds an external dependency (the Lodash library) * May have overhead due to the library itself * Performance might be affected by the size of the input data **Native (`Array.reduce()`):** Pros: * No external dependencies, so no potential performance overhead * Can be more efficient for large datasets, as it avoids the overhead of a library function Cons: * More verbose and less readable code * Requires manual handling of edge cases and error handling **Other considerations** The benchmark also considers the following factors: * The size of the input data (100,000 elements) * The JavaScript engine and browser used for testing (Chrome 116 on Mac OS X 10.15.7) * Device platform (Desktop) **Library: Lodash** Lodash is a popular utility library for JavaScript that provides a set of high-order functions for functional programming. In this benchmark, the `groupBy` function is used to group an array by a specified function. The `groupBy` function takes three arguments: * The input array * A function that returns the grouping key (in this case, the `id` property) * An optional accumulator value (which is not used in this benchmark) **Special JS feature or syntax** There are no special JavaScript features or syntaxes being tested in this benchmark. However, it's worth noting that some modern browsers and JavaScript engines support new features like async/await, decorators, and other advanced syntaxes. Overall, the benchmark provides a useful comparison of two approaches for grouping an array of objects, highlighting the trade-offs between using an external library (Lodash) versus implementing the logic natively.
Related benchmarks:
lodash groupBy vs Array.reduce (2)
lodas2 groupBy vs Array.reduce
lodash groupBy vs Array.reduce on million items
lodash groupBy vs Array.reduce 100k better 2
Comments
Confirm delete:
Do you really want to delete benchmark?