Script Preparation code:
AخA
 
var str = 'abc';
str = str.charAt(Math.floor(Math.random() * 3));
Tests:
  • Switch

     
    switch (str) {
      case 'a': console.log('A'); break;
      case 'b': console.log('B'); break;
      case 'c': console.log('C'); break;
    }
  • Object Literal

    x
     
    const a = () => console.log('A')
    const b = () => console.log('B')
    const c = () => console.log('C')
    const objLiteral = {
      a: a,
      b: b,
      c: c
    }
    objLiteral[str]();
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Switch
    Object Literal

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 5 years ago)
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.87 Safari/537.36
Chrome 78 on Linux
View result in a separate tab
Test name Executions per second
Switch 92319.4 Ops/sec
Object Literal 84619.3 Ops/sec