Loop iteration (length comparison variations) (v18)

Revision 18 of this benchmark created 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
Using static len
for (var i = 0, len = list.length; i < len; i++) {
    var fruit = list[i];
}
ready
contain array
for (var i = 0, a = list, l = a.length; i < l; i++) {
    var fruit = a[i];
}
ready

Revisions

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