Loops - increment vs decrement (v7)

Revision 7 of this benchmark created by Bleeduh 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, 19];
  var temp;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Decrement Loop
for (var i = a.length; i > 0; i--) {
  temp = a[(a.length - i)];
}
ready
Increment Loop
for (var i = 0; i < a.length; i++) {
  temp = a[i];
}
ready
Decrement - one condition
for (var i = a.length; --i;) {
  temp = a[(a.length - i)];
}
ready
Decrement - one condition, one subtraction
for (var i = a.length - 1; i--;) {
  temp = a[i];
}
ready
while loop
var i = a.length - 1;
while (i--) {
  temp = a[i];
}
ready
while loop pre-increment
var i = a.length;
while (--i) {
  temp = a[i];
}
ready

Revisions

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