js loops

JavaScript performance comparison

Revision 11 of this test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var bigArray = [];
  var j = 0;
  for (var i = 0; i < 1000; i++) {
    bigArray.push(i+1);
  }

};
</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
Case 1
for (var i = 0; i < bigArray.length; i++) {
  bigArray[i]++;
}
pending…
Case 2
for (var i = bigArray.length; i--;) {
  bigArray[i]++;
}
pending…
Case 3
for (var i = 0; i < bigArray.length; ++i) {
  bigArray[i]++;
}
pending…
Cached Case 1
var length = bigArray.length;
for (var i = 0; i < length; i++) {
  bigArray[i]++;
}
pending…
Case 4
var length = bigArray.length;
while(length) {
  bigArray[--length]++;
}
pending…
Case 5
for (var i = 0, val; val=bigArray[i]; i++) {
  j++;
}
pending…
forEach
bigArray.forEach(function(item) {
  item++
})
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