Loops - increment vs decrement

JavaScript performance comparison

Test case created by Martin McCool


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

Preparation code

  var a = [1, 43, 65, 7, 3, 2, 6, 8, 9, 5, 10, 2];
  var temp;

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

Compare results of other browsers


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:


Comment form temporarily disabled.

Add a comment