Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
curry examples
(version: 1)
Comparing performance of:
max curry loop args vs max curry recursive args vs curry loop min args vs curry recursive min args
Created:
7 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
function curry1 (f, a = []) { return (...p) => (o => o.length >= f.length ? f(...o) : curry1(f, o))([ ...a, ...p ]) } function curry2(_fn) { if (_fn.length === 0) { return _fn; } const accumArgs = new Array(_fn.length); return nest(_fn, 1, accumArgs); } function nest(_fn, _argN, _accumArgs) { return (..._args) => { let localArgN = _argN - 1; for (let i=0; i<_args.length; i++) { _accumArgs[localArgN] = _args[i]; localArgN ++; if (localArgN === _fn.length) { return _fn(..._accumArgs); } } return nest(_fn, localArgN+1, _accumArgs); }; } function foo (a,b,c,d,e,f) { return a + b + c + d + e + f; }
Tests:
max curry loop args
curry2(foo)(1)(2)(3)(4)(5)(6)
max curry recursive args
curry1(foo)(1)(2)(3)(4)(5)(6)
curry loop min args
curry2(foo)(1, 2, 3, 4, 5, 6)
curry recursive min args
curry1(foo)(1, 2, 3, 4, 5, 6)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
max curry loop args
max curry recursive args
curry loop min args
curry recursive min args
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):
I'll break down the provided benchmark and explain what's being tested. **Benchmark Definition** The benchmark definition is a JSON object that contains two functions: `curry1` and `curry2`. These functions are designed to "curry" another function, meaning they partially apply some of its arguments. * `curry1(f, a = [])`: This function takes another function `f` and an optional array argument `a`. It returns a new function that takes additional arguments `p` and applies them to the original function `f` with the provided initial arguments from `a`. * `curry2(_fn)`: This function takes another function `_fn` and, if it has no arguments left, returns the original function. Otherwise, it creates an accumulator array `accumArgs` and uses a recursive helper function `nest` to apply the remaining arguments. **Benchmark Preparation Code** The preparation code is simply the source code of the two functions (`curry1` and `curry2`) without any modifications. **Options Compared** The benchmark compares four different approaches to curry the function: 1. **`curry1(foo)(1)(2)(3)(4)(5)(6)`**: This approach uses `curry1` with the `foo` function, partially applying 7 arguments. 2. **`curry2(foo)(1, 2, 3, 4, 5, 6)`**: This approach uses `curry2` with the `foo` function, partially applying 6 arguments (less than in `curry1`). 3. **`curry1(foo)(1, 2, 3, 4, 5, 6)`**: This approach is similar to the previous one, but uses `curry1` with only 6 arguments. 4. **`curry2(foo)(1)``` : This approach uses `curry2` with a single argument (less than in the other approaches). **Pros and Cons** * Using `curry1` allows for more flexible partial application, as it can apply any number of additional arguments to the original function. * However, this approach may lead to slower performance due to the overhead of repeated function calls. * `curry2`, on the other hand, is more straightforward but less flexible. It only applies a fixed number of arguments (or none if the function has no arguments left). **Other Considerations** * The benchmark uses Chrome 110 as the test browser, which may have specific optimizations or caching that affect performance. * The `DevicePlatform` and `OperatingSystem` fields are not directly relevant to the performance comparison but provide additional information about the test environment. **Alternatives** If you were to rewrite this benchmark using a different approach, some alternatives could be: * Using a library like Lodash's `curry` function or Ramda's `curry` function, which provides a more concise and efficient way to curry functions. * Implementing a custom currying function using a different algorithm or data structure (e.g., using an array to store the accumulated arguments). * Using a language-specific feature, such as Rust's default argument syntax or Python's `functools.partial`, to simplify the currying process.
Related benchmarks:
test iife
function vs arrow function
Ramda flatten function VS Array.prototype.flat
Inline JS vs Single Function vs Function Composition
Comments
Confirm delete:
Do you really want to delete benchmark?