Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash groupBy test
(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 = 500000; 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:
2 years ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Browser/OS:
Chrome 120 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
lodash
62.2 Ops/sec
native
144.3 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the JavaScript microbenchmark provided by MeasureThat.net. **What is tested?** The benchmark compares two approaches to group data by a specific key: 1. Using the `lodash` library (specifically, the `_groupBy` function) 2. Implementing the grouping logic using native JavaScript (without any external libraries) **Options compared:** * **Lodash:** The `_groupBy` function from the Lodash library is used to group the data by the specified key (`id`). This approach provides a convenient and efficient way to perform grouping, but it relies on an external library. * **Native JavaScript:** The second test case uses native JavaScript to implement the grouping logic. This approach allows for more control over the implementation, but can be slower and more error-prone compared to using a dedicated library like Lodash. **Pros and Cons:** * **Lodash (GroupBy):** + Pros: - Easy to use and understand - Provides an efficient implementation of grouping - Reduces boilerplate code + Cons: - Adds external dependency (lodash library) - May not be the most performant option if optimization is required * **Native JavaScript (GroupBy):** + Pros: - No external dependencies - Provides fine-grained control over implementation - Can be optimized for specific use cases + Cons: - Requires more code and expertise to implement correctly - May be slower or less efficient compared to using a library **Library: Lodash** Lodash is a popular JavaScript utility library that provides a wide range of functions for tasks like array manipulation, string manipulation, and data transformation. The `_groupBy` function is part of this library and takes an array as input, grouping its elements by a specified key. In the benchmark, `lodash.js` is included via a CDN link, allowing users to test the performance of Lodash's `_groupBy` function without downloading any additional dependencies. **Special JavaScript feature:** The benchmark uses ES6 syntax (e.g., `var`, arrow functions) and modern ECMAScript features (e.g., template literals). This suggests that MeasureThat.net supports testing modern JavaScript code and is aware of the latest language features. **Alternatives:** Other alternatives for grouping data in JavaScript include: * Using `Array.prototype.reduce()` method * Implementing a custom `groupBy` function using `forEach`, `map`, or other array methods * Using other dedicated libraries like Ramda, underscore.js (alternative to Lodash), or more specialized tools like Apache Commons Lang Keep in mind that the choice of approach depends on the specific requirements and constraints of your project.
Related benchmarks:
lodash groupBy vs lodash keyBy 2
lodash keyBy and groupBy
lodash groupBy vs Array.reduce 100k better 2
_.groupBy vs Object.groupBy 100k
Comments
Confirm delete:
Do you really want to delete benchmark?