Tests:
  • Object-Function

    AخA
     
    (({
      'object'(){return 'object'},
      'boolean'(){return 'boolean'},
      'function'(){return 'function'},
      'string'(){return 'string'}
    //the condition used to filter an object above
    })[typeof undefined]||(()=>'undefined'))()
  • Object-plain

     
    ({
      'object':'object',
      'boolean':'boolean',
      'function':'function',
      'string':'string'
    //the condition used to filter an object above
    })[typeof undefined]||'undefined'
  • If-Else

     
    if(typeof undefined==='object'){return 'object'} else
    if(typeof undefined==='boolean'){return 'boolean'} else
    if(typeof undefined==='function'){return 'function'} else
    if(typeof undefined==='string'){return 'string'} else {
        return 'undefined'
    }
  • Ternary

     
    typeof undefined==='object'?'object':
    typeof undefined==='boolean'?'boolean':
    typeof undefined==='function'?'function':
    typeof undefined==='string'?'string':
    'undefined';
  • Switch

     
    switch (typeof undefined) {
      case 'object':
        return 'object';
        break;
      case 'boolean':
        return 'boolean'
        break;
      case 'function':
        return 'function';
        break;
      case 'string':
        return 'string';
        break;
      default: 'undefined';
    }
  • Object-Get

     
    ({
      get 'object'(){return 'object'},
      get 'boolean'(){return 'boolean'},
      get 'function'(){return 'function'},
      get 'string'(){return 'string'}
    //the condition used to filter an object above
    })[typeof undefined]||'undefined'
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Object-Function
    Object-plain
    If-Else
    Ternary
    Switch
    Object-Get

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 3 years ago)
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36
Chrome 92 on Linux
View result in a separate tab
Test name Executions per second
Object-Function 3092661.5 Ops/sec
Object-plain 3588023.0 Ops/sec
If-Else 860784.0 Ops/sec
Ternary 752066.1 Ops/sec
Switch 3083611.2 Ops/sec
Object-Get 423700.6 Ops/sec