Another Loop Test

JavaScript performance comparison

Test case created by Liam Mitchell

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var foo = [];
    for (var i = 0; i < 5; i++) {
      foo.push(i);
    }
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Reverse While
var i = foo.length;
while (--i >= 0) {
  console.log(foo[i]);
}
pending…
Reverse For
for (var i = foo.length; i >= 0; --i) {
  console.log(foo[i]);
}
pending…
For
for (var i = 0; i != foo.length; i++) {
  console.log(foo[i]);
}
pending…
do while
var i = foo.length;
do {
  console.log(foo[i])
} while (--i >= 0)
pending…
foreach
foo.forEach(function(index,element) {
  console.log(element);
});
pending…
for cached
var length = foo.length;
for (var i = 0; i != length; i++) {
  console.log(foo[i]);
}
pending…

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

Compare results of other browsers

0 comments

Add a comment