Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
groupBy (ramda vs custom impl)
(version: 0)
Comparing performance of:
ramda vs custom impl
Created:
7 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src="//cdnjs.cloudflare.com/ajax/libs/ramda/0.25.0/ramda.min.js"></script>
Script Preparation code:
function groupBy(n,r){return 1===arguments.length?function(r){return groupBy(n,r)}:r.reduce(function(r,u){var t=n(u);return r[t]?r[t].push(u):r[t]=[u],r},{})} var students = [...Array(3000)].map((v, i) => { return { value: parseInt(Math.random() * 100, 10), score: parseInt(Math.random() * 100, 10) } }) var fn = function(student) { var score = student.score; return score < 65 ? 'F' : score < 70 ? 'D' : score < 80 ? 'C' : score < 90 ? 'B' : 'A'; }
Tests:
ramda
var byGrade = R.groupBy(fn); byGrade(students)
custom impl
var byGrade = groupBy(fn); byGrade(students)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
ramda
custom impl
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.2:3b
, generated one year ago):
Let's break down what's being tested in this benchmark. **What is being tested?** The benchmark is testing the performance of two approaches for grouping data by grade: 1. **Ramda implementation**: The benchmark uses the Ramda library to implement the `groupBy` function. This approach relies on a functional programming style and uses immutable data structures. 2. **Custom implementation**: The second approach implements the `groupBy` function from scratch, without any external libraries. **Options compared** The two approaches are being compared in terms of their performance, which is measured by the number of executions per second. **Pros and cons of each approach** **Ramda implementation:** Pros: * Uses a well-established and widely-used library (Ramda) * Provides a functional programming style that can lead to more concise and expressive code * Immutable data structures can be beneficial for thread-safety and predictability Cons: * Adds an external dependency (the Ramda library) that may not be present in all environments * May have performance overhead due to the use of a separate library **Custom implementation:** Pros: * Eliminates the need for an external library, which can reduce dependencies and improve security * Can provide better control over the implementation details and optimization opportunities Cons: * Requires more manual memory management and handling of mutable data structures * May be less concise or expressive than a well-written functional programming implementation **Library: Ramda** Ramda is a popular JavaScript library for functional programming. It provides a set of higher-order functions that can be used to manipulate and transform data in a predictable and efficient manner. In this benchmark, the `groupBy` function is used to group an array of objects by a common property (in this case, the "score" field). **Special JS feature: None** There are no special JavaScript features or syntaxes being tested in this benchmark. **Benchmark preparation code** The script preparation code defines two functions: * `groupBy(n,r)`: This function takes two arguments (`n` and `r`) and returns a new function that groups an array by the property specified by `r`. If only one argument is provided, it returns the original function. The implementation uses a reduce method to iterate over the array and accumulate the results. * `fn(student)`: This function takes a student object as input and returns a string representing their grade based on their score. The students array is created using an array comprehension, which generates 3000 random student objects with scores between 0 and 100. The `byGrade` variable is assigned to the result of calling the `groupBy` function with the `fn` function as its second argument. **Html preparation code** The HTML preparation code includes a script tag that loads the Ramda library from a CDN. In summary, this benchmark compares the performance of two approaches for grouping data by grade: a Ramda implementation and a custom implementation. The Ramda implementation uses a functional programming style and a separate library, while the custom implementation requires manual memory management and handling of mutable data structures.
Related benchmarks:
lodash groupBy vs Array.reduce vs Ramda on million items
lodash groupBy vs Array.reduce vs Array.group 100k
Reduce with spread VS for...of with push
lodash groupBy vs Array.reduce 100k with gey generation
Comments
Confirm delete:
Do you really want to delete benchmark?