while-vs-for (v23)

Revision 23 of this benchmark created on


Setup

var arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
    var foo = 0;

Test runner

Ready to run.

Testing in
TestOps/sec
while
var i = -1,
  l = arr.length;

while (++i < l) {
  foo++;
}
ready
for
var i = 0,
  l = arr.length;

for (; i < l; i++) {
  foo++;
}
ready
Another while
var i = 0,
  l = arr.length;

while (i < l) {
  foo++;
  i = i + 1;
}
ready
Yet another while
var i = 0,
  l = arr.length;

while (i < l) {
  foo++;
  i++;
}
ready
while loop shift

while (true) {
if(!arr.shift())
break;  
foo++;
}
ready

Revisions

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