window.noop = () => {};
noop();
(() => {})();
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Noop | |
New arrow function |
Test name | Executions per second |
---|---|
Noop | 14610126.0 Ops/sec |
New arrow function | 1027149440.0 Ops/sec |
Let's break down the provided JSON and explain what's being tested, compared, and the pros and cons of each approach.
Benchmark Definition
The benchmark definition is represented by two script preparation codes:
window.noop = () => {};;
- This code creates a new empty function on the global window object and assigns it to the noop
variable.(() => {})();
- This code defines an immediately invoked arrow function expression (IIFE) that returns an empty object.Test Cases
There are two individual test cases:
noop()
function.(() => {})();
.Library and Special JS Features
In this benchmark, no external libraries or special JavaScript features are used.
Benchmark Comparison
The two test cases compare:
window.noop = () => {};;
versus(() => {})();
Both approaches create or define an empty value, but they use different syntax and semantics.
Pros and Cons
window.noop = () => {};;
:(() => {})();
:Other Alternatives
Some alternative approaches could be:
undefined
or null
, to represent an empty value.constant()
function to create a constant value.However, these alternatives might not be relevant in this specific benchmark, as they don't change the fundamental comparison between creating an empty function or an IIFE with a return statement.
Benchmark Results
The latest benchmark result shows that:
(() => {})();
) executed approximately 102.7 million times per second on Chrome 104 on a desktop machine running Mac OS X 10.15.7.noop()
function executed approximately 14.6 million times per second under the same conditions.This suggests that the new arrow function has a better performance profile in this specific benchmark, likely due to its concise syntax and local scope creation.