Run details:
Mozilla/5.0 (iPad; CPU OS 10_0_2 like Mac OS X) AppleWebKit/601.1 (KHTML, like Gecko) CriOS/53.0.2785.109 Mobile/14A456 Safari/601.1.46
Chrome Mobile iOS 53
iOS 10.0.2
iPad
8 years ago
Test name Executions per second
reduce 65.7 Ops/sec
loop 7.0 Ops/sec
loop2 7.1 Ops/sec
Script Preparation code:
AخA
 
t=new Array(500000);
for (let i=0;i<t.length;i++) {t[i]=Math.random();}
Tests:
  • reduce

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

    x
     
    (() => {
      let i=0, res = 0;
    for (;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;})();