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

     
    if(str === 'a'){
        console.log('A'); 
    } else if (str === 'b'){
        console.log('B'); 
    } else if (str === 'c'){
        console.log('C'); 
    }
  • Switch - Case

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

    x
     
    var objLiteral = {
      a: function() {
        console.log('A');
      },
      b: function() {
        console.log('B');
      },
      c: function() {
        console.log('C');
      }
    }
    objLiteral[str]();
  • ternary-operator

     
    str === 'a' ? console.log('A') : str === 'b' ? console.log('B') : str === 'c' ? console.log('C') : console.log('nothing')
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    If - Else
    Switch - Case
    Object literals
    ternary-operator

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 23 days ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36
Chrome 134 on Windows
View result in a separate tab
Test name Executions per second
If - Else 187476.7 Ops/sec
Switch - Case 185697.1 Ops/sec
Object literals 200783.8 Ops/sec
ternary-operator 221315.2 Ops/sec