array iteration (3 cases)

JavaScript performance comparison

Test case created by Darius W.

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var arr = [];
  for (var i = 0; i < 100000; i++) {
      arr[i] = i;
  }
  function testFn (x) {
      return x * 3 - 2;
  }

};
</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
Array.ForEach
arr.forEach(function (item) {
  testFn(item);
});
pending…
For (in)
for (var item in arr) {
    testFn(item);
}
pending…
For (i)
for (var i = 0; i < arr.length; i++) {
    testFn(arr[i]);
}
pending…

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

0 Comments