Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash groupBy vs Array.reduce vs Object.groupBy 100k
(version: 0)
Comparing performance of:
Lodash vs NativeReduce vs NativeGroupBy
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)
NativeReduce
data.reduce((acc, item) => { acc[item.id] = item; return acc; }, {})
NativeGroupBy
Object.groupBy(data, ({ id }) => id)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Lodash
NativeReduce
NativeGroupBy
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; rv:134.0) Gecko/20100101 Firefox/134.0
Browser/OS:
Firefox 134 on Mac OS X 10.15
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash
908.1 Ops/sec
NativeReduce
2124.5 Ops/sec
NativeGroupBy
910.1 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and its test cases. **What is tested:** The provided JSON represents three microbenchmarks that test different approaches to grouping data by an identifier. The benchmarks measure the execution time of each approach: 1. **Lodash groupBy**: Uses the Lodash library (`lodash.js`) to implement a `groupBy` function. 2. **NativeReduce**: A native JavaScript implementation using the `reduce` method. 3. **Object.groupBy** (native): Another native JavaScript implementation that uses the `groupBy` method on objects. **Options compared:** The benchmarks compare the execution time of each approach: * Lodash groupBy * NativeReduce * Object.groupBy (native) Each benchmark is tested with a large dataset (`data`) containing 100,000 objects, where each object has an `id` property. The `max2` variable determines the upper limit of the dataset. **Pros and Cons:** 1. **Lodash groupBy**: * Pros: Lodash provides a convenient and tested implementation that abstracts away the complexity of grouping data. * Cons: Requires including the Lodash library, which may add unnecessary overhead to the test. 2. **NativeReduce**: * Pros: Native JavaScript implementation allows for better performance and control over the algorithm. * Cons: Requires manual implementation of the grouping logic, which can be error-prone and less efficient than the optimized Lodash implementation. 3. **Object.groupBy (native)**: * Pros: Similar to NativeReduce, but uses a more straightforward approach by directly using the `groupBy` method on objects. * Cons: May not be as performant or flexible as NativeReduce. **Library usage:** The `lodash.js` library is used in the Lodash groupBy benchmark. The library provides a convenient implementation of the `groupBy` function, which abstracts away the complexity of grouping data. **Special JS feature/syntax:** None mentioned in this benchmark. However, if there were special features or syntax, they would likely be related to JavaScript's functional programming capabilities, such as arrow functions (`=>`) used in some benchmarks. **Alternatives:** Other approaches for grouping data could include: 1. **D3.js**: A popular data visualization library that provides a `groupBy` function. 2. **Ramda**: Another functional programming library that includes a `groupBy` function. 3. **Manual implementation**: Implementing the grouping logic from scratch, without relying on built-in methods or libraries. Keep in mind that these alternatives may offer different performance characteristics, trade-offs, and use cases compared to the Lodash groupBy, NativeReduce, and Object.groupBy (native) implementations tested in this benchmark.
Related benchmarks:
lodas2 groupBy vs Array.reduce
lodash groupBy vs Array.reduce on million items
lodash groupBy vs Array.reduce 100k with array push
Object.groupBy vs Array.reduce 100k
Comments
Confirm delete:
Do you really want to delete benchmark?