var x = (new Array(100)).fill(0);
function f1() {
return x.map(function(x) {
return x + 1;
});
}
function f2() {
return x.map(g);
}
function g(x) {
return x + 1;
}
f1();
f2();
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
inline | |
cached |
Test name | Executions per second |
---|---|
inline | 99760.0 Ops/sec |
cached | 98351.3 Ops/sec |
Let's break down the provided JSON data and explain what is being tested on MeasureThat.net.
Benchmark Definition
The benchmark definition represents a JavaScript function that performs an operation on an array. The specific function f1
and g
are defined within this benchmark:
function f1() {
return x.map(function(x) {
return x + 1;
});
}
function g(x) {
return x + 1;
}
Here, we have an array x
filled with zeros. Two functions, f1
and g
, are defined to perform a similar operation: mapping the elements of the array to add 1 to each element.
Options Compared
The two main options being compared in this benchmark are:
f1()
function is called inline within the benchmark definition, i.e., f1();
.g
function is stored in a variable and then called using its reference (f2()
) within the benchmark definition.Pros and Cons of Each Approach
Library and Special JS Features
No libraries or special JavaScript features are mentioned in this benchmark. The code is self-contained within the benchmark definition.
Other Alternatives
For those who might be interested, alternative approaches to comparing functions could include:
f1
and g
), a virtual function could be created using a function expression that simply returns a value without performing any actual computation.() => x.map(x => x + 1)
for both f1
and g
) could provide another alternative way to compare the functions.Overall, the MeasureThat.net benchmark provides a simple yet informative example of how different function calling strategies can impact performance.