For Loop Performance: increment vs decrement (v4)

Revision 4 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() {
      let me = this,
          numItems = this.length - 1,
          i = numItems, returnArray = [];
    
      for (; i > -1; i--) {
		returnArray = [...returnArray, me[i]];
      }
      return returnArray;
    }
    
    Array.prototype.loopForward = function() {
      let me = this,
          numItems = this.length,
          i = 0, returnArray = [];
    
      for (; i < numItems; i++) {
        returnArray = [...returnArray, me[i]];
      }
    
      return returnArray;
    }
    
    var states = [...BigInt(1e5).toString()];

Teardown


    var states = [];
  Array.prototype.loopBackward = undefined;
  Array.prototype.loopForward = undefined;

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.