Loop iteration (length comparison variations) (v4)

Revision 4 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
var len = list.length;
for (var i = 0; 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.