Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
partially applied function vs arrow fn curried vs passing arguments every time
(version: 1)
Comparing performance of:
partially applied vs with args vs arrow curried
Created:
2 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
function curried(x) { return function addOne(y) { return x + y } } window._curried = curried(1) function add(x, y) { return x + y } window._add = add const arrowCurried = x => y => x + y window._arrCurr = arrowCurried(1)
Tests:
partially applied
_curried(1)
with args
_add(1, 1)
arrow curried
_arrCurr(1)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
partially applied
with args
arrow curried
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):
**Benchmark Explanation** The provided JSON represents a JavaScript microbenchmark that tests the performance of three different approaches to currying a function: partially applied function, arrow function with curried syntax, and passing arguments every time. **Currying** In functional programming, currying is a technique where a function is transformed into a sequence of smaller functions, each taking only one argument. The resulting functions are then composed together to form the original function. In this benchmark, we have three test cases: 1. **Partially Applied Function**: This approach creates a new function that takes an additional argument, `y`, and returns the result of adding `x` and `y`. The `curried` function is partially applied by calling it with one argument (`x = 1`) using the `_curried` variable. 2. **Arrow Function with Curried Syntax**: This approach defines an arrow function `arrowCurried` that takes two arguments, `x` and `y`, and returns their sum. The `_arrCurr` variable is set to this function by calling it with one argument (`x = 1`). 3. **Passing Arguments Every Time**: In this approach, the original function `add` is called directly with two arguments (`x` and `y`) every time. **Pros and Cons** Here's a brief summary of the pros and cons of each approach: * **Partially Applied Function**: + Pros: Can be useful when working with functions that require an additional argument. + Cons: May incur overhead due to function creation and binding. * **Arrow Function with Curried Syntax**: + Pros: Concise and expressive way to define curried functions. + Cons: May not be immediately clear to readers unfamiliar with currying. * **Passing Arguments Every Time**: + Pros: Simple and straightforward approach. + Cons: Inefficient for repeated function calls, as it incurs overhead due to argument passing. **Library Usage** In the provided code, we see that `window._curried` is assigned a value using the `_curried` variable. This suggests that `_curried` is a library or utility function that partially applies the `curried` function. However, without further information about this library, its purpose and implementation cannot be determined. **Other Considerations** The benchmark uses Chrome 114 as the browser, which may not be representative of other browsers or environments. Additionally, the test cases are designed to measure the performance of each approach, but it's essential to consider other factors that might impact the results, such as: * Function size and complexity * Argument passing overhead * Cache behavior **Alternatives** If you're interested in exploring alternative approaches, here are some alternatives you could consider: * **Lambdas**: In JavaScript, lambdas are anonymous functions that can be defined inline. They provide a concise way to define small functions. * **Method binding**: Method binding is a technique used to create new functions that have the same prototype as an existing function. * **Generators**: Generators are a type of function that allows for iterative processing without explicit loops. Keep in mind that each alternative approach has its own trade-offs, and the choice ultimately depends on the specific requirements and constraints of your project.
Related benchmarks:
Arrow function vs normal function
Arrow function vs normal function comparison fixed
Noop vs new arrow function calls
Arrow function vs function comparison
Arrow functions vs functions
Comments
Confirm delete:
Do you really want to delete benchmark?