for loop research (v73)

Revision 73 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<100000; i++) {
      arr.push('arr-value-' + i);
    }
    
    function worker() {
      return(1+1);
    }

Test runner

Ready to run.

Testing in
TestOps/sec
classic for-loop
for (var i=0; i < arr.length; i++) {
  worker();
}
ready
++i
for (var i=0; i < arr.length; ++i) {
  worker();
}
ready
caching length in loop
for (var i=0, len=arr.length; i<len; i++) {
  worker();
}
ready
caching length outside loop
var len=arr.length;

for (var i=0; i<len; i++) {
  worker();
}
ready
double caching length
var len=arr.length;

for (var i=0, ilen=len; i<ilen; i++) {
  worker();
}
ready
while alternative i--
var i = arr.length;
while (i--) {
  worker();
};
ready
while alternative --i
var i = arr.length;
while (--i) {
  worker();
};
ready

Revisions

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