Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
standard function vs arrow function
(version: 0)
Comparing performance of:
standard function vs arrow function
Created:
5 years ago
by:
Guest
Jump to the latest result
Tests:
standard function
function test1(m) { console.log(m); } test1("hello;");
arrow function
var test2 = (m) => { console.log(m); } test2("hello;");
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
standard 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 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36
Browser/OS:
Chrome 132 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
standard function
86902.1 Ops/sec
arrow function
84203.5 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, the options compared, their pros and cons, and other considerations. **Benchmark Definition** The benchmark is comparing two approaches: standard functions (also known as traditional functions) and arrow functions. The script preparation code for both is empty, which means that any overhead related to function definition will be excluded from the measurement. **Options Compared** 1. **Standard Functions**: Traditional functions in JavaScript are defined using the `function` keyword followed by a name and parameters in parentheses. ```javascript function test1(m) { console.log(m); } test1("hello;"); ``` 2. **Arrow Functions**: Arrow functions, introduced in ECMAScript 2015, are a concise way to define small functions that don't require the `this` keyword or the use of `new`. ```javascript var test2 = (m) => { console.log(m); }; test2("hello;"); ``` **Pros and Cons** * **Standard Functions**: + Pros: Readability, maintainability, and reusability are generally better with traditional functions. + Cons: More verbose, can lead to scope issues due to `this` binding. * **Arrow Functions**: + Pros: Concise, eliminates the need for explicit `this` binding, and reduces code duplication. + Cons: Less readable and maintainable, can be less intuitive for beginners. Other considerations: * **Function expression vs. function declaration**: The benchmark doesn't include a comparison between function expressions (e.g., `var test2 = function(m) { ... }`) and function declarations (e.g., `function test2(m) { ... }`). Function expression is not considered in this benchmark, but it's worth noting that the difference may be noticeable. * **Browser-specific optimizations**: The benchmark runs on Firefox 88, which might have specific optimizations for functions. Other browsers may behave differently. **Library Usage** There are no libraries used in these test cases. **Special JS Features or Syntax** Neither of the test cases uses any special JavaScript features or syntax beyond the standard function and arrow function definitions. **Other Alternatives** If you're interested in exploring other alternatives, here are a few examples: * **Closure**: A closure is a function that has access to its own scope, even when called outside of it. This can be useful for creating private variables. * **Generator functions**: Generator functions allow you to create iterators and handle asynchronous operations more efficiently. * **Async/await**: Async/await syntax makes it easier to write asynchronous code that's easier to read and maintain. Keep in mind that the specific alternatives may not directly relate to the benchmark being measured, but they're worth considering when working with JavaScript.
Related benchmarks:
Arrow function vs normal function comparison
Arrow function vs normal function comparison fixed
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?