switch vs if-else short (v46)

Revision 46 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 'function':
    r = 'function';
    break;
  case 'object':
    r = 'object';
    break;
}
ready
else-if
if (type === 'boolean') {
  r = 'boolean';
} else if (type === 'function') {
  r = 'function';
} else if (type === 'object') {
  r = 'object';
}
ready
and
type === 'boolean' && (r = 'boolean');
type === 'function' && (r = 'function');
type === 'object' && (r = 'object');
ready
if
if (type === 'boolean') {
  r = 'boolean';
}
if (type === 'function') {
  r = 'function';
}
if (type === 'object') {
  r = 'object';
}
ready
else-if with ==
if (type == 'boolean') {
  r = 'boolean';
} else if (type == 'function') {
  r = 'function';
} else if (type == 'object') {
  r = 'object';
}
ready
if with ==
if (type == 'boolean') {
  r = 'boolean';
}
if (type == 'function') {
  r = 'function';
}
if (type == 'object') {
  r = 'object';
}
ready

Revisions

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