Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash groupBy vs Array.reduce 10M
(version: 0)
Comparing performance of:
Lodash vs Native
Created:
5 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 = 10000000; // 10,000,000 (10 Million) var data = []; for (var i = 0; i <= max2; i++) { data.push({ id: i }); }
Tests:
Lodash
_.groupBy(data, ({ id }) => id)
Native
data.reduce((acc, item) => { 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:
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):
Let's break down what's being tested in this JavaScript microbenchmark. **Benchmark Purpose** The benchmark is designed to compare the performance of two approaches: `lodash.groupby()` and `Array.prototype.reduce()`. The test data consists of an array of 10 million objects, each with a unique "id" property. **Options Compared** 1. **Lodash's `groupBy`**: This function groups the input array by a common value extracted from each element using a provided callback function. In this case, the callback extracts the `id` property. 2. **Native `Array.prototype.reduce()`**: This method applies a reduction function to each element of an array, accumulating a result by repeatedly applying the function to the accumulator and the current element. **Pros and Cons** 1. **Lodash's `groupBy`**: * Pros: Lodash is a popular utility library that provides a concise and readable implementation. It's well-maintained and widely used. * Cons: The overhead of importing an external library might be detrimental to performance in some cases. 2. **Native `Array.prototype.reduce()`**: * Pros: This method is built-in, so there's no additional library overhead. It's also a more straightforward, low-level approach that can be optimized by the JavaScript engine. * Cons: The code requires manual implementation of the reduction function, which might lead to errors if not done correctly. **Library Description** The `lodash` library is a popular utility library for JavaScript that provides a wide range of functions for tasks like array manipulation, string manipulation, and more. In this benchmark, it's used to provide a concise implementation of the `groupBy` function. **Special JS Feature/Syntax** There isn't any special JavaScript feature or syntax mentioned in the benchmark code. **Benchmark Preparation Code** The script preparation code creates an array of 10 million objects with unique "id" properties. This is done using a simple `for` loop that pushes objects onto the array. **Other Alternatives** If you were to implement this benchmark without relying on Lodash, you could use other libraries like `underscore.js` or `ramda`, which also provide similar grouping functions. Alternatively, you could write your own implementation of `groupBy` using a simple recursive function or an iterative approach with an object to store the grouped results. Keep in mind that the choice of library or implementation depends on the specific requirements and constraints of your project.
Related benchmarks:
lodash groupBy vs Array.reduce (1mln)
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 with array push
Comments
Confirm delete:
Do you really want to delete benchmark?