Script Preparation code:
AخA
 
var arr = new Array(99999);
Tests:
  • Basic for loop

     
    for (var i=0; i<arr.length; i++) {}
  • For loop but caching the length

     
    for (var i=0, len=arr.length; i<len; i++) {}
  • While loop that imitates a for loop

     
    var i = 0;
    while (i<arr.length) {
        i++;
    }
  • While loop that imitates a for loop caching len

     
    var i=0, len=arr.length;
    while (i<len) {
        i++;
    }
  • While loop in reverse simplifying the test

     
    var i = arr.length; while (i--) {}  
  • While looping by popping values

     
    var x;
    while (x = arr.pop()) {}
  • for ... in loop

     
    for (var i in arr) {}
  • for ... in loop with integer test

     
    var isInt = /(\^[0-9]$)|(\^[1-9][0-9]+$)/;
    for (var i in arr) {
        if(!isInt.test(i)){continue;}
    }
  • For loop testing on existence rather than lengt

     
    for (var i=0; arr[i]; i++) {}   
  • For loop testing on existence plus array lookup

     
    for (var i=0; arr[i]; i++) {
        var x = arr[i];
    }
  • For testing on existence rather than length array

     
    for (var i=0, x; x = arr[i++];) {}  
  • For reference

     
    for (var i=0, len=arr.length; i<len; i++) {
        var x = arr[i];
    }
  • Array.forEach() native implementation.

     
    arr.forEach(function(x){});
  • For reference against forEach()

     
    var f=function(x){};
    for (var i=0, len=arr.length; i<len; i++) {
        f(arr[i]);
    }
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Basic for loop
    For loop but caching the length
    While loop that imitates a for loop
    While loop that imitates a for loop caching len
    While loop in reverse simplifying the test
    While looping by popping values
    for ... in loop
    for ... in loop with integer test
    For loop testing on existence rather than lengt
    For loop testing on existence plus array lookup
    For testing on existence rather than length array
    For reference
    Array.forEach() native implementation.
    For reference against forEach()

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 6 years ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36
Chrome 67 on Windows
View result in a separate tab
Test name Executions per second
Basic for loop 84.0 Ops/sec
For loop but caching the length 13243.2 Ops/sec
While loop that imitates a for loop 85.8 Ops/sec
While loop that imitates a for loop caching len 13581.0 Ops/sec
While loop in reverse simplifying the test 10952.1 Ops/sec
While looping by popping values 6555791.5 Ops/sec
for ... in loop 7380762.0 Ops/sec
for ... in loop with integer test 7075248.5 Ops/sec
For loop testing on existence rather than lengt 7797102.5 Ops/sec
For loop testing on existence plus array lookup 7862444.5 Ops/sec
For testing on existence rather than length array 7607980.5 Ops/sec
For reference 7715308.5 Ops/sec
Array.forEach() native implementation. 7491631.0 Ops/sec
For reference against forEach() 7991575.5 Ops/sec