Test name | Executions per second |
---|---|
reduce | 955924.8 Ops/sec |
for loop | 1080904.0 Ops/sec |
var arrRandom = [];
for(var intCtr=0; intCtr<1000; intCtr++) {
arrRandom.push(Math.floor(Math.random() * Math.floor(100)));
}
function doRedeuce(pArray) {
return pArray.reduce(function(accum, curr) {return accum+curr});
}
function doLoop(pArray) {
var accum = 0;
for(var intCtr=0; intCtr<pArray.length; intCtr++) {
accum += pArray[intCtr];
}
return accum;
}
var redeuceResult=0;
redeuceResult = doRedeuce(arrRandom);
var loopResult=0;
loopResult = doLoop(arrRandom);