Loop traversing index

JavaScript performance comparison

Test case created by Carlos Vázquez

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var i,
      x,
      a = 2,
      b = 1,
      le = 10000;

};
</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 ascending
for(i = 0; i < le; i++) {
    x = a + b;
}
pending…
For descending
for(i = le - 1; i >= 0; i--) {
    x = a + b;
}
pending…
While ascending
i = 0;
while(i++ < le) {
    x = a + b;
}
pending…
While descending
i = le - 1;
while(i-- >= 0) {
    x = a + b;
}
pending…
Do while ascending
i = 0;
do {
    x = a + b;
} while(i++ < le)
pending…
Do while descending
i = le - 1;
do {
    x = a + b;
} while(i-- >= 0)
pending…

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

0 Comments