Iterating over arrays (v11)

Revision 11 of this benchmark created on


Setup

var arr = new Array(1000);
    (function() {
      for (var i = 0; i < arr.length; i++) {
        arr[i] = i;
      }
    }());
    
    var value;

Test runner

Ready to run.

Testing in
TestOps/sec
forEach
arr.forEach(function(x) {
  value = x;
});
ready
for, counting down, caching len
for (var i = arr.length; i--;) {
  value = arr[i];
}
ready
while, counting down
var i = arr.length;
while (--i) {
  value = arr[i];
}
ready
do while, counting down
var i = arr.length - 1;
do {
  value = arr[i];
} while (i--)
ready

Revisions

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