For vs while

JavaScript performance comparison

Test case created

Info

Testing for vs while

Preparation code

<script>  
var i, values = [];

  for (i = 0; i < 1000; i++) {
    values[i] = 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
While
var len = values.length, cnt = 0;
while (len--) {
  cnt++;
}
pending…
For
var cnt = 0;
for (var i = 0, len = values.length; i <= len; i++) {
  cnt++;
}
pending…
For not equal comparison
var cnt = 0;
for (var len = values.length - 1, i = 0; i != len; i++) {
 cnt++;
}
pending…
For not equal comparison and increment
var cnt = 0;
for (var len = values.length - 1, i = 0; i++ != len;) {
 cnt++;
}
pending…
While not equal
var len = values.length, cnt = 0;
while (len-- != 0) {
  cnt++;
}
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