get sub type

Benchmark created on


Description

testing json key locate vs switch case vs object literals

Setup

const interviewTypeToSubTypeMap = {
  'remote': 'Reminder2',
  'remote2': 'Reminder2',
  'phone': 'Reminder3',
  'phone2': 'Reminder3',
  'in-person': 'Reminder1',
  'in-person2': 'Reminder1',
};

function isInPerson () {
    return 'Reminder1';
  }
function isRemote () {
    return 'Reminder2';
  }
  
function isPhone () {
    return 'Reminder3';
  }

const interviewTypeToSubTypeLiteral = {
  'remote': isRemote,
  'remote2': isRemote,
  'phone': isPhone,
  'phone2': isPhone,
  'in-person': isInPerson,
  'in-person2': isInPerson
};

Test runner

Ready to run.

Testing in
TestOps/sec
json key locate
function getSubType(type) {
  return interviewTypeToSubTypeMap[type];
}

const type = 'in-person';
const subType = getSubType(type);
ready
switch case
function getSubType(type) {
  switch (type) {
    case 'remote':
    case 'remote2':
      return 'Reminder2';
    case 'phone':
    case 'phone2':
      return 'Reminder3';
    case 'in-person':
    case 'in-person2':
      return 'Reminder1';
    default:
      return undefined;
  }
}


const type = 'in-person';
const subType = getSubType(type);
ready
object literal
function getSubType(type) {
  return interviewTypeToSubTypeLiteral[type]
}


const type = 'in-person';
const subType = getSubType(type);
ready

Revisions

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