loop-in-js-2

Benchmark created on


Setup

Benchmark.prototype.setup = function() {
    var array = new Array(), 
    i = 0;
    
    for (i; i < 1000; i++)
    array.push(i);
    
    var len = array.length;
    };

Test runner

Ready to run.

Testing in
TestOps/sec
for
for (var i = 0; i < len; i++) {
  array[i] = 0;
}
ready
while
var i = 0;
while (i < len) {
  array[i] = 0;
  i++;
}
ready
do - while
var i = 0;

do {
  array[i] = 0;
} while (i++ < len);
ready
for in
for (var i in array) {
  array[i] = 0;
}
ready
for-revers
for (var i = len; i--;) {
array[i] = 0;
}
ready
for-each
array.forEach(function(idx){
array[idx] = 0;
})
ready

Revisions

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