Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodas2 groupBy vs Array.reduce
(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 = 1000000; // 100,000,000 (100 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:
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
39.7 Ops/sec
Native
112.1 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and explain what's being tested. **Benchmark Overview** The benchmark is comparing two approaches to group data by an identifier: using Lodash's `groupBy` function and using the native JavaScript `reduce` method. The benchmark creates a large dataset of objects with an `id` property, ranging from 0 to 100 million, and then tests which approach can process this data more efficiently. **Options Compared** Two options are being compared: 1. **Lodash's `groupBy` function**: This is a utility function that groups an array of objects by a key function. In this case, the key function is a simple identity function (`id`) that returns the `id` property of each object. 2. **Native JavaScript `reduce` method**: This is a built-in method that applies a reducer function to each element in an array, accumulating a result. **Pros and Cons** Here's a brief summary of the pros and cons of each approach: * **Lodash's `groupBy` function**: + Pros: Easy to use, efficient, and well-tested. + Cons: Adds an additional dependency (the Lodash library), which may not be desirable for all developers or in production environments. * **Native JavaScript `reduce` method**: + Pros: No additional dependencies, highly optimized by the browser's engine. + Cons: Requires more code to implement, and its performance can vary depending on the specific use case. **Library - Lodash** Lodash is a popular utility library for JavaScript that provides a wide range of functions for tasks like array manipulation, string processing, and object transformation. In this benchmark, Lodash's `groupBy` function is used to group the data by the `id` property. **Special JS Feature/Syntax - None** There are no special JavaScript features or syntax being tested in this benchmark. The code is straightforward and easy to understand for any software engineer familiar with JavaScript. **Other Alternatives** If you're looking for alternative approaches to group data, here are a few options: * **D3.js's `groupby` function**: A part of the D3.js library, which is specifically designed for data visualization. * **Pako's `groupBy` function**: Another utility library that provides a `groupBy` function. * **Array.prototype.reduce() with a custom key function**: While this approach requires more code to implement, it can be an alternative to using Lodash or D3.js. In summary, the benchmark is comparing two approaches to group data: using Lodash's `groupBy` function and using the native JavaScript `reduce` method. The results will help determine which approach is faster and more efficient for this specific use case.
Related benchmarks:
lodash groupBy vs Array.reduce (1mln)
lodash groupBy vs Array.reduce (2)
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?