FizzBuzz35

JavaScript performance comparison

Test case created

Info

Note some will produce "FizzBuzz" and some
Fizz
Buzz

Preparation code

<script type="text/javascript">
var console = {
    log : function(x){return x;}
};
</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
two level
var i = 0;
while( ++i < 21 ){
    if ( i % 3 === 0 ) {
        if ( i % 5 === 0 ) console.log('FizzBuzz'); // Special case
        else console.log('Fizz');
    }
    else if ( i % 5 === 0 ) {
        console.log('Buzz');
    }
    else console.log(i);
}
pending…
one level
for(var i = 1; i <= 20; i = i + 1) {
    if(i%3==0)  {
        console.log("Fizz");
    }
    if (i%5==0){
        console.log("Buzz");
    }
    if (i%5 && i%3) {
        console.log(i);
    }
}
pending…
special
for(var i = 1; i <= 20; i = i + 1){
    var special = false;
    if (i%3==0) {
        console.log("Fizz");
        special = true
    }
    if (i%5==0){
        console.log("Buzz");
        special = true;
    }
    if (!special) {
        console.log(i);
    }
}
pending…
str
for(var i = 1; i <= 20; i = i + 1){
    var tolog = '';
    if (i%3==0) {
        tolog += "Fizz";
    }
    if (i%5==0){
        tolog += "Buzz";
    }
    console.log(tolog || 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