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 126.6 Ops/sec
loop 5.5 Ops/sec
loop2 5.5 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;})();