Loop iteration (length comparison variations)

JavaScript performance comparison

Revision 21 of this test case created by Maurizio Manetti

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 CCBot 2.0.0 / Other 0.0.0
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…
Using reverse while
var i = list.length;
while (i-=1) {
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.

0 Comments