For Loop Speed Test (v6)

Revision 6 of this benchmark created on


Description

Check for loops for impacts on JS performance. Note when using a for loop as illustrated in Example 3 then this kind of loop would stop when a "falsy" item is found.

Preparation HTML

<script>
  var items = [],
      test;
  
  for (var i = 0; i < 10000; i++) {
    items[i] = [i];
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Example 1
for (var x = 0; x < items.length; x++) {
  test = items[x];
}
ready
Example 2
for (var y = 0, len = items.length; y < len; y++) {
  test = items[y];
}
ready
Example 3
for (var z = 0; test = items[z]; z++);
ready

Revisions

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