Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Arrow function vs normal function vs function declaration comparison
(version: 0)
Comparing performance of:
Arrow function vs Normal function vs Function declaration
Created:
3 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
arrowFn = (a, b) => a + b; fn = function(a, b) { return a + b; }; function fnDef(a, b) { return a + b; }
Tests:
Arrow function
arrowFn()
Normal function
fn()
Function declaration
fnDef()
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Arrow function
Normal function
Function declaration
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
10 months ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36
Browser/OS:
Chrome 138 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Arrow function
239130688.0 Ops/sec
Normal function
268718880.0 Ops/sec
Function declaration
281565792.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'd be happy to explain the benchmark and its results. **Benchmark Overview** The benchmark measures the performance of three different JavaScript functions: arrow function, normal function (also known as traditional function), and function declaration. The goal is to compare their execution speeds in different browsers and environments. **Script Preparation Code** The script preparation code defines three functions: 1. `arrowFn`: an arrow function that takes two arguments and returns their sum. 2. `fn`: a traditional function (using the `function` keyword) that also takes two arguments and returns their sum. 3. `fnDef`: a function declaration (without the `function` keyword) that takes two arguments and returns their sum. The script preparation code is similar in all three cases, which means that only the syntax differences between arrow functions, traditional functions, and function declarations affect their execution speeds. **Library and Special JS Features** There are no libraries or special JavaScript features used in this benchmark. The focus is solely on comparing the performance of different JavaScript function types. **Test Cases** The benchmark consists of three test cases: 1. `arrowFn()`: tests the arrow function 2. `fn()`: tests the traditional function 3. `fnDef()`: tests the function declaration Each test case measures the execution speed of its respective function type in different browsers and environments. **Results Analysis** The latest benchmark results show that: * Function declarations (`fnDef`) are the fastest, with an average execution speed of 5187960 executions per second. * Normal functions (`fn`) come next, with an average execution speed of 5310448 executions per second. * Arrow functions (`arrowFn`) have the slowest performance, with an average execution speed of 10419500 executions per second. This suggests that function declarations are generally faster than traditional functions and arrow functions in this specific benchmark. **Pros and Cons** Here are some pros and cons for each approach: 1. Function Declaration (fastest): * Pros: concise syntax, easy to read and write. * Cons: limited flexibility and expressiveness compared to other options. 2. Normal Function: * Pros: flexible and expressive syntax, widely supported by browsers and engines. * Cons: verbose syntax can lead to performance issues in some cases. 3. Arrow Function (slowest): * Pros: concise syntax, easy to write and read. * Cons: limited flexibility and expressiveness compared to other options. **Alternatives** Other alternatives for creating functions include: 1. Anonymous Functions (using the `()` syntax): these are similar to arrow functions but can be used with different syntax. 2. Closures: a function that can capture variables from its outer scope, often used in complex scenarios. However, in this benchmark, only three specific function types were compared, and arrow functions have some unique characteristics that make them distinct from other options. I hope this explanation helps! Let me know if you have any further questions.
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
Arrow function vs normal function comparison 3
Comments
Confirm delete:
Do you really want to delete benchmark?