For or while (v26)

Revision 26 of this benchmark created by Mads Stoumann on


Preparation HTML

<script>
  var foo = [];
  var cnt = 0;
  var i = 5000;

  while(i--) foo.push(i);
  
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
for
for (var i = 0; i < foo.length; i++) {
  cnt = foo[i];
}
 
ready
while
var i = foo.length;
while (i--) {
  cnt = foo[i];
}
 
ready
reverse for
for (var i = foo.length; i > 0; i--) {
  cnt = foo[i];
}
 
ready
for cached
var i, n = foo.length;
for (i = 0; i < n; i++) {
  cnt = foo[i];
}
 
ready
reverse for cached
var i = foo.length;
for (; i--;) {
  cnt = foo[i];
}
 
ready
forEach
foo.forEach(function(i){cnt = i;});
ready

Revisions

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