Loop iteration (length comparison variations)

JavaScript performance comparison

Test case created

Info

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

Preparation code

<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

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Using list.length
for (var i = 0; i < list.length; i++) {
    var fruit = list[i];
}
pending…
Using static len
for (var i = 0, len = list.length; i < len; i++) {
    var fruit = list[i];
}
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment