(new Function('return true'))()
(()=>true)()
(function test(){return true})()
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
new function | |
function (arrow) | |
function |
Test name | Executions per second |
---|---|
new function | 2467527.5 Ops/sec |
function (arrow) | 996896768.0 Ops/sec |
function | 1003863488.0 Ops/sec |
Let's break down what's being tested in the provided JSON benchmark.
Benchmark Purpose
The goal of this benchmark is to compare the performance of three different approaches to creating and executing anonymous functions:
new Function()
=>
syntax)new
or arrow syntax)Options Compared
Here's a brief overview of each option:
Function()
is used to create a new anonymous function, which is immediately invoked.=>
) allows for concise and expressive functions without the need for a traditional function declaration or new
keyword.()
is used.Pros and Cons of Each Approach
Here are some pros and cons for each approach:
Library Use
None of the test cases use external libraries. However, it's worth noting that some browsers might include additional JavaScript libraries or resources when running these benchmarks.
Special JS Features
There are no special JavaScript features used in this benchmark.
Benchmark Preparation Code and Execution
The provided JSON benchmark definitions outline the specific scripts to be executed for each test case:
new Function('return true')
: Creates a new anonymous function using Function()
and immediately invokes it with the argument 'return true'
.=>true()
: Defines an arrow function with the expression true
and immediately invokes it.(function test(){return true})()
: Creates a traditional function declaration with a single statement (test()
) that returns true
, which is then invoked.Benchmark Results
The latest benchmark results show the performance metrics for each test case, including:
These results likely indicate the relative performance of each approach across different browsers, devices, and platforms.