if-v-for

JavaScript performance comparison

Test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var a = [ 1, 2, 3, 4, 5 ],
        b = [ 1 ];
   
    function run_if ( a ) {
        var l = a.length;
   
        if ( l === 1 ) {
           return;
        }
   
   
        for ( var i = 0; i < l; i++ ) {
        }
    }
   
    function run_for ( a ) {
        var l = a.length;
   
        for ( var i = 0; i < l; 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
if
run_if( a );
run_if( b );
pending…
for
run_for( a );
run_for( b );
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