Compare for loop vs while loop

JavaScript performance comparison

Revision 21 of this test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var a = [];
  for(var i = 1; i <= 10000; i++) a.push(i);

};
</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
for basic
var length = a.length;
while(length){length += -1;}
pending…
for cached 1
var length = a.length, i = 0;
for(; length > i;){i += 1;}
pending…
for cached 2
var length = a.length,
i = 0;
for(; i < length;){i+=1;}
pending…
for basic reverse
for(var i = a.length; i--;){}
pending…
for cached 1 reverse
var length = a.length;
for(;length;){length-=1;}
pending…
for cached 2 reverse
var length = a.length;
for(; length;){--length;}
pending…
while basic
var i = 0;
while(i < a.length){ i++; }
pending…
while chached
var length = a.length,
i = 0;
while(i < length){ i++; }
pending…
while reverse
var length = a.length;
while(length){length -= 1;}
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