if vs switch vs object

JavaScript performance comparison

Revision 3 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
if
var a = 10;
if (a == 1) {
console.log(a);
} else if (a == 2) {
console.log(a);
} else if (a == 3) {
console.log(a);
} else if (a == 4) {
console.log(a);
} else if (a == 5) {
console.log(a);
} else if (a == 6) {
console.log(a);
} else if (a == 7) {
console.log(a);
} else if (a == 8) {
console.log(a);
} else if (a == 9) {
console.log(a);
} else if (a == 10) {
console.log(a);
} else  {
console.log(-1);
}
pending…
switch
var a = 10;

switch (a) {
case 1:
  console.log(a);
  break;
case 2:
  console.log(a);
  break;
case 3:
  console.log(a);
  break;
case 4:
  console.log(a);
  break;
case 5:
  console.log(a);
  break;
case 6:
  console.log(a);
  break;
case 7:
  console.log(a);
  break;
case 8:
  console.log(a);
  break;
case 9:
  console.log(a);
  break;
case 10:
  console.log(a);
  break;
default:
  console.log(-1);
}
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