Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36
Chrome 53
Windows
Other
8 years ago
Test name Executions per second
reduce 925384.4 Ops/sec
loop 55058.5 Ops/sec
loop2 57060.7 Ops/sec
Script Preparation code:
AخA
 
t = [];
for (let i=0; i < 50; i++) t.push(Math.random());
Tests:
  • reduce

     
    t.reduce((p,c) => p+c, 0);
  • loop

    x
     
    (() => {
    let res = 0;
    for (let i=0;i<t.length;i++) res += t[i];
    return res;})();
  • loop2

     
    (() => {
    var i, res;
    for (i=res=0;i<t.length;i++) res += t[i];
    return res;})();