forloopopttests

Benchmark created by Ian Schoonover on


Setup

var arr = [
      "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"
  ];

Test runner

Ready to run.

Testing in
TestOps/sec
normal for loop
for(var i = 0; i < arr.length; i++) {
  console.log(arr[i]);
}
ready
opt 1
for(var i = 0, length = arr.length; i < length; i++) {
  console.log(arr[i]);
}
ready
opt 2
var i;
var length = arr.length;

for(i = 0; i < length; i++) {
  console.log(arr[i]);
}
ready
opt 3
var i = 0,
    length = arr.length;

for(; i < length; i++) {
  console.log(arr[i]);
}
ready

Revisions

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

  • Revision 1: published by Ian Schoonover on