chained vs nested

JavaScript performance comparison

Test case created

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Chained
for ( var i = 1, limit = 100, byThree, byFive; i <= limit; i++ ) {
        byThree = i % 3 === 0;
        byFive = i % 5 === 0;

        if ( !byThree && !byFive ) {
                console.log( i );
        } else {
                if ( byThree && byFive ) {
                        console.log( "FizzBuzz" )
                } else {
                        if ( byThree ) {
                                console.log( "Fizz" )
                        } else {
                                console.log( "Buzz" )
                        }
                }
        }
}
pending…
Nested
for ( var i = 1, limit = 100, byThree, byFive; i <= limit; i++ ) {
        byThree = i % 3 === 0;
        byFive = i % 5 === 0;

        if ( byThree && byFive ) {
                console.log( "FizzBuzz" );
        } else {
                if ( byThree ) {
                        console.log( "Fizz" )
                } else if ( byFive ) {
                        console.log( "Buzz" );
                } else {
                        console.log( 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