The loops

JavaScript performance comparison

Revision 15 of this test case created

Info

Is the "reverse while" really faster than a normal for loop? And if yes, how much?

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var iterations2 = 100,
        a = 0,
        i, iterations;
};
</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, ne, subtraction
i = iterations2;
while (i !== 0) {
  a = a + 1;
  a = a - 1;
  i--;
}
 
pending…
while, ne, addition
i = 0;
while (i !== iterations2) {
  a = a + 1;
  a = a - 1;
  i++;
}
pending…
for-loop, lt, addition
for(i=0; i < iterations2; i++) {
    a = a + 1;
    a = a - 1;
}
pending…
for-loop, ne, addition
for(i=0; i !== iterations2; i++) {
    a = a + 1;
    a = a - 1;
}
pending…
for-loop, gt, subtraction
for(i=iterations2; i > 0; i--) {
    a = a + 1;
    a = a - 1;
}
pending…
for-loop, ne, subtraction
for(i=iterations2; i !== 0; i--) {
    a = a + 1;
    a = a - 1;
}
pending…
while, gt, subtraction
i = iterations2;
while (i > 0) {
  a = a + 1;
  a = a - 1;
  i--;
}
 
pending…
while, lt, addition
i = 0;
while (i < iterations2) {
  a = a + 1;
  a = a - 1;
  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. Here’s a list of current revisions for this page:

0 comments

Add a comment