Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Arrow function vs normal function comparison [2.1]
(version: 0)
Comparing performance of:
Arrow function vs Normal function
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
let a1 = 1 let a2 = 2 createArrow = function () { return (a, b) => a + b + a1; } createRegular = function () { return function(a, b) { return a + b + a2; }; } arrowFn = createArrow(1) regularFn = createRegular(2)
Tests:
Arrow function
arrowFn()
Normal function
regularFn()
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Arrow function
Normal function
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
6 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.0.1 Safari/605.1.15
Browser/OS:
Safari 26 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Arrow function
88325184.0 Ops/sec
Normal function
92050976.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided JSON to understand what's being tested. **Benchmark Definition** The benchmark is comparing two approaches to creating functions: Arrow Functions (`createArrow`) and Normal Functions (`createRegular`). **Options Compared** * **Arrow Function**: A compact, syntax-defined function that has a shorter signature compared to normal functions. It uses the `=>` operator to separate the parameters from the body. * **Normal Function**: A traditional, non-compact function definition that uses curly brackets `{}` and has a longer signature. **Pros and Cons** * **Arrow Functions**: + Pros: More concise syntax, less overhead due to no need for explicit `this` binding, and can be used as methods on objects. + Cons: Can only contain single expression bodies (e.g., `return` statements), and some limitations with `super` and destructuring. * **Normal Functions**: + Pros: More flexible syntax, can have more complex logic, and supports `super`, destructuring, and more. + Cons: Longer signature, potentially less readable due to the need for explicit `this` binding. **Library Used** There is no library explicitly mentioned in the benchmark definition. The functions are defined using native JavaScript syntax. **Special JS Feature/Syntax** There's no special feature or syntax being tested beyond what's already mentioned (arrow functions and normal functions). **Other Alternatives** To compare the performance of arrow functions and normal functions, you could consider other approaches: * **Lambdas**: Similar to arrow functions but might have slightly different optimizations. Some JavaScript engines optimize lambdas differently than regular function expressions. * **Closure-based functions**: Using closures to create functions can lead to differences in optimization compared to simple function expressions or arrow functions. **Benchmark Preparation Code** The script preparation code defines two functions, `createArrow` and `createRegular`, which return different types of functions. The `arrowFn` variable is created by calling `createArrow(1)`, while the `regularFn` variable is created by calling `createRegular(2)`. **Individual Test Cases** The test cases are designed to measure the performance of each function type (arrow and normal functions). The benchmark result shows that Firefox 131 performs slightly better with arrow functions than with normal functions. When interpreting the results, consider factors like: * Your specific use case: Are you working on a project where concise syntax is crucial? Or do you need more flexibility in your code? * Browser support: Different browsers might optimize these functions differently. * Performance implications: For small scripts or performance-critical code paths, the differences between arrow and normal functions might not be significant.
Related benchmarks:
Arrow function vs normal function comparison fixed
Arrow function vs normal named function comparison
Arrow function vs normal function comparison 2
Arrow function vs function comparison
Comments
Confirm delete:
Do you really want to delete benchmark?