Switch vs If (v3)

Revision 3 of this benchmark created on


Description

The if variant should really use else if for every statement but the first to be compatible with the switch statement.

Setup

var a="object";

Test runner

Ready to run.

Testing in
TestOps/sec
switch
switch (a) {
  case "s":
        break;
  case "n":
        break;
  case "b":
        break;
  case "object":
        console.log('ok');
        break;
}
ready
if
if (a === 's') {

}
else if (a === 'n') {

}
else if (a === 'b') {

}
else if (a === 'object') {
  console.log('ok');
}
ready

Revisions

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