Script Preparation code:
x
 
// Create an array of 1000 random intergers between 1 and 10000
var arrRandom = [];
for(var intCtr=0; intCtr<1000; intCtr++) {
  arrRandom.push(Math.floor(Math.random() * Math.floor(10000)));
}
function reduceCallback(accum, curr) {
    accum.push(curr);
    return accum;
}
function doRedeuce(pArray) {
    return pArray.reduce((arr, item) => {
        arr.push(item);
        return arr;
    }, []);
}
function doLoop(pArray) {
    var accum = [];
    for(var intCtr=0; intCtr<pArray.length; intCtr++) {
        accum.push(pArray[intCtr]);
    }
    return accum;
}
function doForEach(pArray) {
    var accum = [];
    pArray.forEach(function(item) {
        accum.push(item)
    });
}
Tests:
  • reduce

     
    var redeuceResult=[];
    redeuceResult = doRedeuce(arrRandom);
  • foreach

     
    var forEachResult=[];
    forEachResult = doForEach(arrRandom)
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    reduce
    foreach

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 4 years ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.135 Safari/537.36
Chrome 84 on Windows
View result in a separate tab
Test name Executions per second
reduce 251704.8 Ops/sec
foreach 253826.8 Ops/sec