Compare for loop vs while loop

JavaScript performance comparison

Revision 10 of this test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var a = new Array(5000000);
  for(var i = 0; i < a.length; ++i) a[i] = 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
for(var i = 0; i < a.length; i++){}
pending…
for cached
var length = a.length;
for(var i = 0; i < length; i++){}
pending…
for compact
for(var i = -1; ++i < a.length;){}
pending…
for cached-compact
for(var i = -1, len = a.length; ++i < len;){}
pending…
while basic
var i = 0;
while(i < a.length){ i++; }
pending…
while cached
var length = a.length,
i = 0;
while(i < length){ i++; }
pending…
while compact
var i = -1;
while(++i < a.length){}
pending…
while cached/compact
var i = -1, len = a.length;
while(++i < len){}
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