Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36
Chrome 87
Mac OS X 10.15.7
Desktop
4 years ago
Test name Executions per second
for loop 159459.7 Ops/sec
reverse while loop 158903.6 Ops/sec
Script Preparation code:
AخA
 
var array = [];
(function () {
  var length = 100;
  while (length--) {
    array.push(Math.random());
  }
})();
Tests:
  • for loop

    x
     
    var i = 0;
    var length = array.length;
    for (; i < length; i++) {
      array[i]++;
    }
  • reverse while loop

     
    var i = array.length;
    while (i--) {
      array[i]++;
    }