Slow loop (v8)

Revision 8 of this benchmark created on


Description

Comparing the "slow loop" argument from http://www.sitepoint.com/google-closure-how-not-to-write-javascript/

Preparation HTML

<script>
  var arr = [];
  for (var i = 1; i <= 10000; i++) {
    arr.push(i);
  }
  
  var result = -1;
  
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
"Slow" loop
for (var i = 0; i < arr.length; i++) {
  result = i;
}
ready
"Fast" loop
for (var i = 0, len = arr.length; i < len; i++) {
  result = i;
}
ready
"Fastest" loop
var i = arr.length;
while (i--) {
  result = i;
}
ready
"Slowest" loop
for (var i = 0, num; num = arr[i++];) {
  result = i;
}
ready
?? loop
var i = arr.length;
do {
result = i;
} while (i--);
ready

Revisions

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