Loops - increment vs decrement

JavaScript performance comparison

Revision 9 of this test case created

Info

Tests the speed gains when decrementing through a loop vs incrementing through a loop.

Preparation code

<script>
  var a = [1, 43, 65, 7, 3, 2, 6, 8, 9, 5, 10, 2];
  var aIndex = a.length;
</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
Decrement Loop
for (var i = aIndex; --i >= 0;) {
  console.log(i);
}
pending…
Increment Loop
for (var i = 0; i < aIndex; i++) {
  console.log(i);
}
pending…
Increment Loop 2
for (var i = 0; ++i >= aIndex;) {
  console.log(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