FizzBuz

JavaScript performance comparison

Revision 4 of this test case created

Info

better fizz

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Fizzbuz
function fizzbuzz(i) {
  var lookup = [null, "fizz", "buzz", "fizzbuzz"];
  var mask = (!(i % 5) << 1) ^ (!(i % 3));
  return lookup[mask] || i;
}
pending…
Old
function fizzBuzz(number) {

  if (number % 3 !== 0) {
    if (number % 5 !== 0) {
      return number;
    }
    return 'buzz';
  }
  if (number % 5 !== 0) {
    return 'fizz';
  }

  return 'fizzbuzz';
};
pending…
Bitwise2
function fizzbuzz(i) {
  var lookup = [null, "fizz", "buzz", "fizzbuzz"],
    acc = 810092048;
  var c = acc & 3;
  acc = acc >> 2 | c << 28;
  return lookup[c] || i;

}
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment