fizzBuzzJsTechniques

JavaScript performance comparison

Test case created by samonela

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
original
for(var i=1;i<=100;i++) {
var output = "";

    if(i % 15 == 0) {output = "FizzBuzz"}
    else if(i % 3 == 0) {output = "Fizz"}
    else if(i % 5 == 0) {output = "Buzz"}
    else {output = i;}

console.log(output);
}
pending…
function
function fizzBuzz(value) {
    if (value % 15 === 0) return "FizzBuzz";
    if (value % 3 === 0) return "Fizz";
    if (value % 5 === 0) return "Buzz";
    return value;
}
for (var i = 1; i <= 100; i++) {
    console.log(fizzBuzz(i));
}
pending…
function with string append
function fizzBuzz(value) {
    var output = "";
    if (value % 3 === 0) output += "Fizz";
    if (value % 5 === 0) output += "Buzz";
    return output || value;
}
for (var i = 1; i <= 100; i++) {
    console.log(fizzBuzz(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