FizzBuz

JavaScript performance comparison

Revision 3 of this test case created

Info

better fizz

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var lookup = [null, "fizz", "buzz", "fizzbuzz"],
      acc = 810092048;
};
</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
Fizzbuz
function fizzbuzz(i) {
  var mask = (!(i % 5) << 1) ^ (!(i % 3));
  return !mask ? i : lookup[mask];
}
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 c = acc & 3;
  var ret = lookup[c] || i;
  acc = acc >> 2 | c << 28;
  return ret;
}
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