Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
GroupBy 100k: Ramda, Underscore, Array.reduce
(version: 2)
Comparing performance of:
Ramda vs Reduce vs Underscore
Created:
6 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/ramda/0.27.0/ramda.min.js'></script> <script src='https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js'></script>
Script Preparation code:
// var underscore = _.noConflict(); var max2 = 100000; var data = []; for (var i = 0; i <= max2; i++) { data.push({ id: i, name: 'Bob' }); } function testFn (el){ return el.id }
Tests:
Ramda
R.groupBy(el => el.id, data)
Reduce
data.reduce( (previousValue, currentValue, currentIndex, array, k = testFn(currentValue)) => ( (previousValue[k] || (previousValue[k] = [])).push(currentValue), previousValue ), {}, );
Underscore
_.groupBy(data, ({ id }) => id)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Ramda
Reduce
Underscore
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.1:latest
, generated one year ago):
Let's break down the provided JSON and benchmark results. **Benchmark Definition** The benchmark tests three different approaches to group an array of objects by their `id` property: 1. **Ramda**: Uses the `groupBy` function from the Ramda library, which is a JavaScript library for functional programming. 2. **Reduce**: Uses the `reduce` method on the array, with a custom reducer function that groups elements based on their `id`. 3. **Underscore**: Uses the `groupBy` function from the Underscore library, another popular JavaScript library. **Library Descriptions** * **Ramda**: A lightweight functional programming library for JavaScript. In this benchmark, it's used to implement a concise grouping function. * **Underscore**: A utility belt library that provides various methods for working with arrays and objects. The `groupBy` function is one of its features. * **Array.reduce**: This benchmark also uses the built-in `reduce` method on JavaScript arrays, which combines all elements into a single output. **JS Features/Syntax** There are no special JS features or syntax used in this benchmark beyond what's provided by standard JavaScript and the libraries mentioned above. **Pros/Cons Comparison** Here's a brief comparison of the three approaches: * **Ramda**: Pros - concise, expressive code; Cons - requires an additional library (albeit lightweight). * **Reduce**: Pros - uses built-in array method; Cons - potentially slower due to recursive function calls. * **Underscore**: Pros - another popular and widely-used library with good support; Cons - adds another dependency. **Other Alternatives** For grouping arrays, you could also consider: 1. **LoDash**: Another popular utility library that might offer better performance or more features than Underscore. 2. **JavaScript's built-in `reduce` method with a custom reducer function**, similar to the Reduce test case in this benchmark. 3. **Using a simple loop and object initialization** for a more basic, yet efficient approach. Keep in mind that the best choice ultimately depends on your project requirements, coding style preferences, and performance considerations.
Related benchmarks:
lodash groupBy vs Array.reduce (1mln)
lodash groupBy vs Array.reduce vs Ramda on million items
lodash groupBy vs lodash keyBy 2
lodash keyBy and groupBy
Comments
Confirm delete:
Do you really want to delete benchmark?