Run details:
Mozilla/5.0 (iPhone; CPU iPhone OS 10_0_1 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) Version/10.0 Mobile/14A403 Safari/602.1
Mobile Safari 10
iOS 10.0.1
iPhone
8 years ago
Test name Executions per second
reduce 34.1 Ops/sec
loop 3.3 Ops/sec
loop2 3.3 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;})();