Array Looping Performance Check

JavaScript performance comparison

Test case created by Ed Bishop

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var arr = [];
  count = 1000000;
  while(count--) {
    arr.push(count);
  }
  
  function calc(n){
    return 3*n/10+6;
  }

};
</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
for
for(var i = 0; i < arr.length; i++) {
  calc(arr[i]);
}
pending…
for-cached-prefix-let
for (let i = 0, len = arr.length; i < len; ++i) {
  calc(arr[i]);
}
pending…
for-cached-prefix-var
for (var i = 0, len = arr.length; i < len; ++i) {
  calc(arr[i]);
}
pending…
for-length-caching
for (var i = 0, len = arr.length; i < len; i++) {
  calc(arr[i]);
}
pending…
for-reverse
for(var i = arr.length - 1; i >= 0; i--) {
  calc(arr[i]);
}
pending…
while-let
let i = 0;
while(i < arr.length) {
  calc(arr[i]);
  i++;
}
pending…
while-var
var i = -1;
while(++i < arr.length) {
  calc(arr[i]);
}
pending…

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

0 Comments