Loops - increment vs decrement

JavaScript performance comparison

Test case created by Martin McCool

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 temp;
</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 = 10; i > 0; i--) {
 temp = a[(10 - i)];
}
pending…
Increment Loop
for (var i = 0; i < 10; i++) {
 temp = a[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