Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash `groupBy()` vs `Object.groupBy()`
(version: 0)
Comparing performance of:
Lodash groupBy vs Object.groupBy
Created:
one year 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>
Tests:
Lodash groupBy
const items = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21]; console.log(_.groupBy(items, (item) => item % 3));
Object.groupBy
const items = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21]; console.log(Object.groupBy(items, (item) => item % 3));
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Lodash groupBy
Object.groupBy
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
4 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:146.0) Gecko/20100101 Firefox/146.0
Browser/OS:
Firefox 146 on Mac OS X 10.15
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash groupBy
287434.6 Ops/sec
Object.groupBy
281229.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the explanation of the benchmark. **What is tested on the provided JSON?** The benchmark compares two approaches to implement the `groupBy()` method in JavaScript: 1. **Lodash**: Lodash is a popular JavaScript library that provides a wide range of utility functions, including `groupBy()`. The benchmark tests how fast and efficient Lodash's implementation is compared to the built-in `Object.groupBy()` method. 2. **Built-in `Object.groupBy()` method**: This is the native JavaScript method for grouping arrays by a key function. **Options compared** The benchmark compares two options: 1. **Lodash's `groupBy()` method** 2. **Built-in `Object.groupBy()` method** **Pros and cons of each approach** **Lodash's `groupBy()` method** Pros: * Well-maintained and widely used library, ensuring stability and performance. * Provides additional features and utility functions beyond just grouping. Cons: * Adds an extra dependency to the application (the Lodash library). * May introduce overhead due to the library's additional functionality. **Built-in `Object.groupBy()` method** Pros: * No additional dependency or overhead. * Native implementation, ensuring optimal performance and execution speed. Cons: * Not as widely used or well-maintained as Lodash. * Limited features compared to Lodash. **Other considerations** Both approaches have their trade-offs. If you prioritize simplicity and don't need additional utility functions from Lodash, the built-in `Object.groupBy()` method might be a better choice. However, if you want a more comprehensive library with additional features and benefits, Lodash's implementation might be worth the extra dependency. **Special JS feature or syntax** Neither of the tested approaches utilizes any special JavaScript features or syntax beyond standard ECMAScript 2015 (ES6) syntax. **Library and its purpose** The `Object.groupBy()` method is a built-in JavaScript function that groups an array by a specified key function. It returns an object where each property is an array of values from the original array, grouped by the provided key function. In the context of this benchmark, Lodash's implementation of `groupBy()` provides a more comprehensive and feature-rich solution, but it comes with the added overhead of using an external library. **Alternatives** Other alternatives to implement `groupBy()` in JavaScript include: 1. **Underscore.js**: Another popular JavaScript library that provides various utility functions, including `groupBy()`. 2. **Array.prototype.groupby()`: Some browsers and Node.js implementations provide a custom `groupBy()` method on the Array prototype. 3. **Custom implementation**: You can also implement the `groupBy()` method from scratch using standard ECMAScript 2015 (ES6) syntax. Keep in mind that these alternatives may have different trade-offs, dependencies, or performance characteristics compared to Lodash and the built-in `Object.groupBy()` method.
Related benchmarks:
Lodash groupBy vs JS reduce
lodash groupBy vs Array.reduce on million items
lodash groupBy vs Array.reduce grouping
lodash groupBy vs Array.reduce vs Object.groupBy 100k
_.groupBy vs Object.groupBy 100k
Comments
Confirm delete:
Do you really want to delete benchmark?