Fastest Array Loops (v52)

Revision 52 of this benchmark created on


Setup

var arr = [],
      a = 0;
  
  for (; a < 1000; a += 1) {
    arr[a] = a;
  }
  
  function doStuff(x) {
    return (x + x);
  }

Test runner

Ready to run.

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

Revisions

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