Script Preparation code:
AخA
 
var arr = Array(10_000).fill(0)
Tests:
  • reduce with new array

     
    arr.reduce((acc, x) => [...acc, x, x], [])
  • reduce with array mutation

     
    arr.reduce((acc, x) => { acc.push(x); return acc; }, [])
  • flatMap

     
    arr.flatMap(x => [x, x])
  • for

     
    const newArray = [];
    for (let i = 0; arr.length > i; i++) {
      newArray.push(arr[i]);
    }
  • for-of

     
    const newArray = [];
    for (let x of arr) {
      newArray.push(x);
    }
  • map

     
    arr.map(x => x);
  • forEach

     
    const newArray = [];
    arr.forEach(x => newArray.push(x));
  • values (iterates over for-of)

     
    const newArray = [];
    for (let x of arr.values()) {
      newArray.push(x);
    }
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    reduce with new array
    reduce with array mutation
    flatMap
    for
    for-of
    map
    forEach
    values (iterates over for-of)

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: one year ago)
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36
Chrome 117 on Linux
View result in a separate tab
Test name Executions per second
reduce with new array 7.1 Ops/sec
reduce with array mutation 19090.0 Ops/sec
flatMap 330.6 Ops/sec
for 781.8 Ops/sec
for-of 23622.9 Ops/sec
map 27197.0 Ops/sec
forEach 19834.1 Ops/sec
values (iterates over for-of) 24433.1 Ops/sec