Slow loop (v20)

Revision 20 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 = new Uint8Array(10000),
a;
  for (var i = 0; i < 10000; i++) {
    arr[i] = i;
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
"Slow" loop
for(var i = 0; i < arr.length; i++)
{
  a = arr[i];
}
ready
"Fast" loop
var l = arr.length
for (var i = 0; i < l; i++)
{
 a = arr[i];
}
ready
"Fastest" loop
var l = arr.length;
while (l--)
{
  a = arr[l];
}
ready

Revisions

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