modulo calculations

JavaScript performance comparison

Revision 2 of this test case created by

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
normal
var out = '';
for (var i = 1; i <= 100; i++) {
  out = '';
  if (i % 3 == 0) {
    out = 'Fizz';
  }
  if (i % 5 == 0) {
    out += 'Buzz';
  }
  if (!out) {
    out = i;
  }
}
pending…
nested
var out = '';
for (var i = 1; i <= 100; i++) {
  if (i % 3 == 0 && i % 5 == 0) {
    out = 'FizzBuzz';
  }
  else if (i % 3 == 0) {
    out = 'Fizz';
  }
  else if (i % 5 == 0) {
    out = 'Buzz';
  } else {
    out = i;
  }
}
pending…
cached results
var out = '', mod3 = 0, mod5 = 0;
for (var i = 1; i <= 100; i++) {
  mod3 = i % 3 == 0;
  mod5 = i % 5 == 0;

  if (mod3 && mod5) {
    out = 'FizzBuzz';
  }
  else if (mod3) {
    out = 'Fizz';
  }
  else if (mod5) {
    out = 'Buzz';
  } else {
    out = i;
  }
}
pending…
oposite nested
for (var i = 1; i <= 100; i++) {
  if (i % 3 != 0 && i % 5 != 0) {
    out = i;
  }
  else if (i % 3 == 0 && i % 5 != 0) {
    out = 'Fizz';
  }
  else if (i % 5 == 0 && i % 3 != 0) {
    out = 'Buzz';
  } else {
    out = 'FizzBuzz';
  }
}
pending…
cached oposite nested
var out = '', mod3 = 0, mod5 = 0;
for (var i = 1; i <= 100; i++) {
  mod3 = i % 3 == 0;
  mod5 = i % 5 == 0;
  if (!mod3 && !mod5) {
    out = i;
  }
  else if (mod3 && mod5) {
    out = 'Fizz';
  }
  else if (mod5 && !mod3) {
    out = 'Buzz';
  } else {
    out = 'FizzBuzz';
  }
}
pending…
cached oposite nested
var out = '', mod3 = 0, mod5 = 0;
for (var i = 1; i <= 100; i++) {
  mod3 = i % 3 == 0;
  mod5 = i % 5 == 0;
out = '';
  if (!mod3 && !mod5) {
    out = i;
  }
  else {
if (mod3) {
    out = 'Fizz';
  }
  if (mod5) {
    out += 'Buzz';
  }
}
}
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.

0 Comments