Fastest Array Loops (v48)

Revision 48 of this benchmark created by Terry Anastasiadis on


Setup

// Populate the base array
  var arr = [];
  for (var i = 0; i < 1000; i += 1) {
    arr.push( 0.9999999999999999 );
  }
  //Something to do...
  function doStuff(x) {
    return (x * x * x);
  }

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.