HTML Preparation code:
AخA
 
1
<script>
2
    Benchmark.prototype.setup = function() {
3
        var testData = [];
4
        for (var i = 0; i < 100; i++) {
5
            testData.push(i);
6
        }
7
    };
8
</script>
Tests:
  • forEach

     
    var res = 0;
    testData.forEach(function(x) {
      res += x;
    });
  • for

     
    var res = 0;
    for (var i = 0; i < testData.length; i++) {
      res += testData[i];
    }
  • for optimized

     
    var res = 0;
    for (var i = 0, len = testData.length; i < len; i++) {
      res += testData[i];
    }
  • reduce

     
    var res = testData.reduce(function(sum, x) {
      return sum + x;
    }, 0);
  • while

     
    var res = 0;
    var i = testData.length;
    while (i--) {
        res += testData[i];
    }
  • for in

     
    var res = 0;
    for (var data in testData) {
      res += testData[i];
    }
  • for of

     
    var res = 0;
    for (var data of testData) {
      res += testData[i];
    }
  • for of babel

    x
     
    var res = 0;
    var _iteratorNormalCompletion = true;
    var _didIteratorError = false;
    var _iteratorError = undefined;
    try {
      for (var _iterator = testData[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
        var value = _step.value;
        console.log(value);
      }
    } catch (err) {
      _didIteratorError = true;
      _iteratorError = err;
    } finally {
      try {
        res += testData[i];
        if (!_iteratorNormalCompletion && _iterator.return) {
          _iterator.return();
        }
      } finally {
        if (_didIteratorError) {
          throw _iteratorError;
        }
      }
    }
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    forEach
    for
    for optimized
    reduce
    while
    for in
    for of
    for of babel

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: one month ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Chrome 131 on Mac OS X 10.15.7
View result in a separate tab
Test name Executions per second
forEach 7415045.0 Ops/sec
for 16116002.0 Ops/sec
for optimized 16133428.0 Ops/sec
reduce 15813537.0 Ops/sec
while 11888596.0 Ops/sec
for in 776158.1 Ops/sec
for of 6115275.5 Ops/sec
for of babel 3203.0 Ops/sec