js loops

JavaScript performance comparison

Test case created by Arash Milani

Preparation code


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

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

3 Comments

kave commented :

xxxx

michael commented :

Why Case 1 (not cashed) is faster then cashed case? I do not understand it.

michael commented :

I mean FF 18