var array1 = [1, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16],
map1 = [],
arrayLength = array1.length;
for (var i = 0; i < arrayLength; i++) {
map1[i] = array1[i] * 2;
}
var array1 = [1, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16];
var map1 = array1.map(x => x * 2);
var array1 = [1, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16];
var map1 = array1.map(function (x) {return x * 2});
var array1 = [1, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16, 4, 9, 16],
map1 = [],
arrayLength = array1.length;
for (var i = 0; i < arrayLength; i++) {
map1.push(array1[i] * 2);
}
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
For loop bracket notation | |
Map new notation | |
Map old notation | |
For loop push |
Test name | Executions per second |
---|---|
For loop bracket notation | 229711.9 Ops/sec |
Map new notation | 235476.1 Ops/sec |
Map old notation | 230885.7 Ops/sec |
For loop push | 219590.4 Ops/sec |
A long and detailed test result!
It seems that the tests are comparing the performance of three different methods:
map()
with an arrow function to create a new array with double values.map()
without an arrow function, which is the legacy syntax.for
loop with brackets ([]
) to iterate over the array and push double values to a new array.for
loop without brackets to iterate over the array and push double values to a new array.The test results show that:
It's worth noting that the performance differences between these methods are relatively small, and may not be significant in all cases. However, the results suggest that using map()
with arrow functions (new notation) can provide a small performance boost compared to older syntax or traditional for
loop methods.