Loop iteration (length comparison variations) (v14)

Revision 14 of this benchmark created by Curtis on


Description

Comparison of different ways to treat the length of an array when iterating the array.

Preparation HTML

<script>
  var list = [
      "oranges",
      "apples",
      "tangerines",
      "watermelon",
      "nectarines",
      "peaches",
      "strawberries",
      "oranges",
      "apples",
      "tangerines",
      "watermelon",
      "nectarines",
      "peaches",
      "strawberries",
      "oranges",
      "apples",
      "tangerines",
      "watermelon",
      "nectarines",
      "peaches",
      "strawberries",
      "oranges",
      "apples",
      "tangerines",
      "watermelon",
      "nectarines",
      "peaches",
      "strawberries"
  ];
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Using list.length
for (var i = 0; i < list.length; i++) {
    var fruit = list[i];
}
ready
Variables outside of the for loop
var i = 0,
    len = list.length;

for (; i < len; i++) {
    var fruit = list[i];
}
ready

Revisions

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