Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Regular vs arrow functions
(version: 0)
Comparing performance of:
Regular function vs Assigned function vs Arrow function
Created:
2 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
arrowFn = (a, b) => a + b; assignedFn = function(a, b) { return a + b; }; function regularFn(a, b) { return a + b; };
Tests:
Regular function
regularFn()
Assigned function
assignedFn()
Arrow function
arrowFn()
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Regular function
Assigned function
Arrow function
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36
Browser/OS:
Chrome 129 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Regular function
25219564.0 Ops/sec
Assigned function
12276274.0 Ops/sec
Arrow function
13584125.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and explain what's being tested. **Benchmark Definition** The benchmark consists of three test cases: 1. `regularFn()`: A traditional JavaScript function definition using the `function` keyword. 2. `assignedFn()`: An assigned function definition using the `var`, `let`, or `const` keywords to declare a variable and attach a function to it. 3. `arrowFn()`: An arrow function definition, which is a shorthand way of defining small, single-expression functions. **Options being compared** The benchmark is comparing three different ways of defining functions: * Traditional function definitions using the `function` keyword (`regularFn()`). * Assigned function definitions using variables (`assignedFn()`). * Arrow function definitions (`arrowFn()`). These approaches differ in their syntax and performance characteristics. Let's discuss the pros and cons of each approach: **Traditional Function Definitions** Pros: * Widespread support across browsers and JavaScript engines. * Easy to read and understand for developers familiar with traditional function definitions. Cons: * Can lead to slower execution times due to the overhead of creating a new function object. * May not be as efficient as other approaches, especially for small functions. **Assigned Function Definitions** Pros: * Can improve performance by reusing existing function objects. * Can reduce memory allocation and deallocation. Cons: * Syntax can be less readable and maintainable for developers unfamiliar with assigned functions. * Not all browsers or JavaScript engines support assigned functions (although most modern ones do). **Arrow Functions** Pros: * Concise syntax that eliminates the need for a separate `function` keyword. * Can improve performance by reusing existing function objects, similar to assigned functions. Cons: * Syntax can be less readable and maintainable for developers unfamiliar with arrow functions. * Not all browsers or JavaScript engines support arrow functions (although most modern ones do). **Library usage** There is no explicit library mentioned in the benchmark definition. However, it's worth noting that some browsers may use internal libraries to optimize function execution. **Special JS features** The benchmark does not appear to use any special JavaScript features beyond traditional function definitions and arrow functions. It does not include modern features like `async/await`, generators, or decorators. **Other alternatives** If the developers wanted to explore alternative approaches for defining functions, they could consider using: * Generator functions: Allow for more concise syntax and improved performance. * Closures: Allow for more complex function definitions and can improve performance in certain cases. * Method expressions: Provide a shorthand way of defining methods on objects. However, these alternatives may require additional support or configuration in the browser or JavaScript engine being used. In summary, the benchmark is testing three common approaches to defining functions in JavaScript: traditional function definitions, assigned function definitions, and arrow functions. Each approach has its pros and cons, and understanding these differences can help developers optimize their code for better performance and maintainability.
Related benchmarks:
Arrow function vs normal function comparison
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?