switch vs if-else short (v55)

Revision 55 of this benchmark created on


Description

Going to exclude "typeof" performance looses

Setup

var type = "object";

Test runner

Ready to run.

Testing in
TestOps/sec
switch
switch (type) {
  case 'boolean': r = 'boolean';
    break;
  case 'object': r = 'object';
    break;
}
ready
else-if
if (type == 'boolean') {
  r = 'boolean';
} else if (type == 'object') {
  r = 'object';
}
ready
and
type == 'boolean' && (r = 'boolean');
type == 'object' && (r = 'object');
ready
if
if (type == 'boolean') {
  r = 'boolean';
}
if (type == 'object') {
  r = 'object';
}
ready
else
if (type == 'boolean') {
  r = 'boolean';
} else {
  r = 'object';
}
ready
ternary
r = (type == 'boolean') ? 'boolean' : 'object';
ready

Revisions

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