var arrowFn = (a, b) => a + b;
function fn(a, b) {
return a + b;
}
arrowFn(1,2)
fn(1,2)
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
arrowFn | |
fn |
Test name | Executions per second |
---|---|
arrowFn | 16493125.0 Ops/sec |
fn | 16849512.0 Ops/sec |
Let's break down the benchmark and its results to understand what's being tested.
Benchmark Definition
The benchmark is comparing two approaches: arrow functions and traditional functions (also known as function expressions). Both are used to define small, single-purpose functions that take two arguments (a
and b
) and return their sum.
Script Preparation Code
The script preparation code provides the implementation for both the arrow function (arrowFn
) and the traditional function (fn
). The main difference between them is how they declare their function body:
(a, b) => a + b
this
binding)function fn(a, b) { return a + b; }
Html Preparation Code
There is no HTML preparation code provided, so we can assume that the benchmark only focuses on JavaScript performance.
Individual Test Cases
We have two test cases:
arrowFn(1, 2)
fn(1, 2)
These test cases call each function with specific input arguments and measure their execution time.
Latest Benchmark Result
The results show the performance of both functions on a Chrome 109 browser on a Mac OS X 10.15.7 device:
Test Name | ExecutionsPerSecond |
---|---|
fn | 164,93125.0 |
arrowFn | 168,49512.0 |
Library and Special JS Features
There are no libraries or special JavaScript features mentioned in the benchmark definition.
Other Alternatives
For a more comprehensive understanding of function performance in JavaScript, you may want to explore benchmarks for other aspects, such as:
Some popular resources for JavaScript performance benchmarking include:
Keep in mind that benchmarking is an active area of research, and results may vary depending on the specific use case and environment.