Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Reduce vs Object.groupBy
(version: 0)
Testing the new native method
Comparing performance of:
New native groupBy vs Old native reduce
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var max2 = 100000; var data = []; for (var i = 0; i <= max2; i++) { data.push({ id: i }); }
Tests:
New native groupBy
Object.groupBy(data, ({ id }) => id)
Old native reduce
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
New native groupBy
Old native reduce
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
8 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:142.0) Gecko/20100101 Firefox/142.0
Browser/OS:
Firefox 142 on Mac OS X 10.15
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
New native groupBy
181.4 Ops/sec
Old native reduce
655.9 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 Definition** The benchmark is testing two different approaches to achieve the same result: reducing an array of objects to a grouped object using either the `Object.groupBy` method (new native) or the `reduce` method (old native). **Test Cases** There are two test cases: 1. **New native groupBy**: This test case uses the new native `Object.groupBy` method to group the data array by the `id` property of each object. 2. **Old native reduce**: This test case uses the old native `reduce` method to achieve the same result as `Object.groupBy`. **Options Compared** The two approaches are compared in terms of performance, which is measured by the number of executions per second. **Pros and Cons** * **Object.groupBy (New Native)**: + Pros: This approach is likely to be faster because it's a native method optimized for performance. + Cons: It may not work in older browsers or environments that don't support this feature. * **Reduce (Old Native)**: + Pros: This approach is widely supported by most browsers and environments, making it a safe choice. + Cons: It might be slower than `Object.groupBy` due to the overhead of looping through each element. **Library and Purpose** There is no library mentioned in this benchmark. However, the use of `Object.groupBy` suggests that the test is targeting modern browsers or environments that support this feature. **Special JS Feature or Syntax** No special JavaScript features or syntax are used in these test cases. They're relatively simple and straightforward. **Other Considerations** * The test data is created by pushing 100,000 objects onto an array, with each object having a unique `id` property. * The benchmark uses Chrome 124 as the target browser, which suggests that the test is optimized for this specific version. * The test only runs on desktop platforms, which might limit its relevance to mobile or other device types. **Alternatives** If you were to create a similar benchmark, you could consider adding additional test cases, such as: * Using a different data structure, like an array of arrays * Adding more complex data structures, like nested objects * Testing the performance of these methods in different browsers or environments Keep in mind that the specific approach and data used will impact the results of your benchmark.
Related benchmarks:
Reduce with spread VS for...of with push
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?