Tests:
  • New array with spread

    x
     
    const testData = [...Array(100000).keys()];
    const evens = testData.reduce((acc, v) => {
      if(v % 2 === 0) {
        acc = [...acc, v];
      }
      return acc;
    }, []);
    console.log(evens.length);
  • Accumulator push

     
    const testData = [...Array(100000).keys()];
    const evens = testData.reduce((acc, v) => {
      if(v % 2 === 0) {
        acc.push(v);
      }
      return acc;
    }, []);
    console.log(evens.length);
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    New array with spread
    Accumulator push

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 2 years ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36
Chrome 104 on Mac OS X 10.15.7
View result in a separate tab
Test name Executions per second
New array with spread 0.2 Ops/sec
Accumulator push 156.7 Ops/sec