for vs while vs forEach loop (v266)

Revision 266 of this benchmark created by add for of 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
for of
for (var value of list) {
  x += value;
}
ready

Revisions

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