Loops - increment vs decrement (v9)

Revision 9 of this benchmark created on


Description

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

Preparation HTML

<script>
  var a = [1, 43, 65, 7, 3, 2, 6, 8, 9, 5, 10, 2];
  var aIndex = a.length;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Decrement Loop
for (var i = aIndex; --i >= 0;) {
  console.log(i);
}
ready
Increment Loop
for (var i = 0; i < aIndex; i++) {
  console.log(i);
}
ready
Increment Loop 2
for (var i = 0; ++i >= aIndex;) {
  console.log(i);
}
ready

Revisions

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