Loop iteration (length comparison variations) (v3)

Revision 3 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
decrement
for (var i = list.length; 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.