Fastest Array Loops (v49)

Revision 49 of this benchmark created on


Setup

var arr = [];
  
  for (var i = 0; i < 1000; i += 1) {
    arr.push('?');
  }
  
  function doStuff(x) {
    //simple!
  }

Test runner

Ready to run.

Testing in
TestOps/sec
While, length -= 1
var l = arr.length;
while (l -= 1) {
  doStuff(arr[l]);
}
ready
While, i += 1
var i = 0,
    l = arr.length;
while (i < l) {
  doStuff(arr[i]);
  i += 1;
}
ready
For, i += 1
for (var i = 0, l = arr.length; i < l; i += 1) {
  doStuff(arr[i]);
}
ready
For, outter, i += 1
var i = 0,
    l = arr.length;
for (; i < l; i += 1) {
  doStuff(arr[i]);
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.