for loop research (v23)

Revision 23 of this benchmark created on


Description

Varius for-loop variants: * with length caching * with various counter increment (++i, i++) * while alternative

Setup

var arr = [];
    
    for (var i = 0; i < 1000; i++) {
      arr.push('arr-value-' + i);
    }
    
    function worker() {
      return (1 + 1);
    }

Test runner

Ready to run.

Testing in
TestOps/sec
while i--
var i = arr.length;
while (i) {
  i--;
  worker();
};
 
ready
while --i;
var i = arr.length;
while (i) {
  --i;
  worker();
};
 
ready
while i -= 1;
var i = arr.length;
while (i) {
  i -= 1;
  worker();
};
 
ready

Revisions

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