if vs switch js (v2)

Revision 2 of this benchmark created on


Setup

var x = Math.floor(Math.random() * 5),
      y = 0;

Test runner

Ready to run.

Testing in
TestOps/sec
if-else
if (x === 1) {
  y = x + 1;
} else if (x === 2) {
  y = x + 2;
} else {
  y = x + 10;
}
ready
switch
switch (x) {
  case 1:
    y = x + 1;
    break;
  case 2:
    y = x + 2;
    break;
  default:
    y = x + 10;
    break;
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.