for vs while vs forEach loop (v265)

Revision 265 of this benchmark created by Krinkle on


Setup

var i,
      x = 0;
      list = [];
    
    
    for (i = 0; i < 2000; i++) {
      list[i] = Math.random();
    }

Test runner

Ready to run.

Testing in
TestOps/sec
forEach
list.forEach(function(value) {
  x += value;
});
ready
for
for (i = 0; i < list.length; i++) {
  x += list[i];
}
ready
for w/ cached length
var len = list.length;
for (i = 0; i < len; i++) {
  x += list[i];
}
ready
for (reverse)
for (i = list.length - 1; i >= 0; i--) {
  x += list[i];
}
ready
while (reverse)
i = list.length;
while (i--) {
  x += list[i];
}
ready

Revisions

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