Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
_.groupBy vs Object.groupBy 100k
(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 = 100000; var data = []; for (var i = 0; i <= max2; i++) { data.push({ id: i }); }
Tests:
Lodash
_.groupBy(data, ({ id }) => id)
Native
Object.groupBy(data, ({ id }) => id)
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:
12 days ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Safari/537.36
Browser/OS:
Chrome 147 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash
321.0 Ops/sec
Native
42.6 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'd be happy to help explain the JavaScript microbenchmark on MeasureThat.net. **Overview** The benchmark measures the performance of two approaches for grouping data: Lodash's `groupBy` function and the native JavaScript `Object.groupBy` method. The test case consists of creating an array of 100,000 objects with unique IDs and then comparing the execution times of these two grouping functions. **Options Compared** There are only two options being compared: 1. **Lodash's `groupBy` function**: This is a popular utility library that provides a concise way to group data based on a specific property. 2. **Native JavaScript `Object.groupBy` method**: This is the built-in function in modern JavaScript that allows grouping data using a similar syntax to Lodash. **Pros and Cons** Here are some pros and cons of each approach: **Lodash's `groupBy` function:** Pros: * Concise syntax * Robust error handling (e.g., handles missing properties) * Well-tested and widely used Cons: * Adds overhead due to the library's dependencies and complexity * May not be optimized for performance in all cases **Native JavaScript `Object.groupBy` method:** Pros: * Faster execution times, as it's a built-in function with native optimization * No additional dependencies or overhead Cons: * Less concise syntax (requires more code) * More prone to errors if property names are not correct **Library and Purpose** The Lodash library is a popular utility library that provides a wide range of functions for working with data, arrays, and objects. In this case, the `groupBy` function is used to group an array of objects based on a specific property. **Special JavaScript Feature or Syntax** There isn't any special JavaScript feature or syntax being tested in this benchmark. However, it's worth noting that some browsers may have different behavior when using certain features like arrow functions (which are used in the `groupBy` function). **Other Alternatives** If you're interested in exploring alternative grouping methods, here are a few options: * **Array.prototype.reduce()**: You can use `reduce()` to group data by iterating over the array and accumulating results. * ** Array.prototype.forEach()**: Similar to `reduce()`, you can use `forEach()` to iterate over the array and perform grouping operations. * **Other libraries**: There are many other utility libraries available that provide grouping functions, such as Ramda or Immutable.js. I hope this explanation helps!
Related benchmarks:
lodash groupBy vs Array.reduce on million items
lodash groupBy vs Array.reduce 100k better 2
lodash groupBy vs Array.reduce vs Object.groupBy 100k
Object.groupBy vs Array.reduce 100k
Comments
Confirm delete:
Do you really want to delete benchmark?