js loops

JavaScript performance comparison

Revision 14 of this test case created

Info

Checking the real performance difference for the various javascript loops patterns.

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 unknown unknown
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…
Cached code 2
var length = bigArray.length;
for(var i=0; i < length; i+=1){
    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. Here’s a list of current revisions for this page:

0 comments

Add a comment