Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Safari/605.1.15
Safari 16
Mac OS X 10.15.7
Desktop
one year ago
Test name Executions per second
reduce 6738364.5 Ops/sec
loop 161457.6 Ops/sec
loop2 159848.8 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;})();