Script Preparation code:
AخA
 
function getRandomInt(max) {
  return Math.floor(Math.random() * Math.floor(max));
}
Tests:
  • Switch

     
    let x= "";
    const i = getRandomInt(6);
    switch(i) {
      case 0: x= "Zero"; break;
      case 1: x= "One"; break;
      case 2: x= "Two"; break;
      case 3: x= "Three"; break;
      case 4: x= "Four"; break;
      case 5: x= "Five"; break;
    }
  • If (else)

    x
     
    let x = "";
    const i = getRandomInt(6);
    if (i === 0) x = "Zero"
    else if (i === 1) x = "One"
    else if (i === 2) x = "Two"
    else if (i === 3) x = "Three"
    else if (i === 4) x = "Four"
    else if (i === 5) x = "Five"
  • Object selector

     
    let x = "";
    const i = getRandomInt(6);
    x = {
      0: "Zero",
      1: "One",
      2: "Two",
      3: "Three",
      4: "Four",
      5: "Five",
    }[i];
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Switch
    If (else)
    Object selector

    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/96.0.4664.110 Safari/537.36
Chrome 96 on Linux
View result in a separate tab
Test name Executions per second
Switch 1255065.9 Ops/sec
If (else) 1271773.8 Ops/sec
Object selector 1280706.1 Ops/sec