For Loop Performance: increment vs decrement (v3)

Revision 3 of this benchmark created on


Description

I want to know if decrementing a for-loop is really faster than incrementing it.

Setup

Array.prototype.loopBackward = function(searchString) {
      var me = this,
          numItems = this.length,
          i, returnArray = [];
    
      for (i = numItems - 1; i >= 0; i--) {
        returnArray.push(me[i]);
      }
      return returnArray;
    }
    
    Array.prototype.loopForward = function(searchString) {
      var me = this,
          numItems = this.length,
          i, returnArray = [];
    
      for (i = 0; i <= numItems - 1; i++) {
        returnArray.push(me[i]);
      }
    
      return returnArray;
    }
    
    var states = ["Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "Florida", "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey", "New Mexico", "New York", "North Dakota", "North Carolina", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming"];

Teardown


    var states = [];
  

Test runner

Ready to run.

Testing in
TestOps/sec
For-Loop Decremented
states.loopBackward();
ready
For-Loop Incremented
states.loopForward();
ready

Revisions

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