while vs forr

JavaScript performance comparison

Revision 2 of this test case created by Tim Vermaelen

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var a = [1, 2, 3, 4, 5, 6, 7, 8];

};
</script>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
while
var i = -1,
    n = a.length;
while (++i < n) {
  a[i];
};
pending…
for i++
for (var i = 0, n = a.length; i < n; i++) {
  a[i];
};
pending…
for ++i
for (var i = -1, n = a.length; i < n; ++i) {
  a[i];
};
pending…
while--
var len = a.length;
while (len--) {
  a[len];
}
pending…
for i++ (2)
var i = 0,
    n = a.length;
for (i; i < n; i++) {
  a[i];
};
pending…

Compare results of other browsers

Revisions

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

0 Comments