Test Loops

JavaScript performance comparison

Test case created by Josh Goodwin

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var testArray = [];
    for ( var i = 0; i<10000; i++ )
        testArray.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
regular For Loop
for ( var i=0, ii=testArray.length; i<ii; i++) {}
pending…
Zakas Loop
for ( var i=testArray.length; i--; ) {}
pending…
Old for
for ( var i = 0; i<testArray.length; i++ ) {}
pending…

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

Compare results of other browsers

0 comments

Add a comment