Tests:
  • switch case

    x
     
    function thing(e) {
        switch (e) {
          case 0:
            return "0";
          case 1:
            return "1";
          case 2:
            return "2";
          case 3:
            return "3";
            
          default: 
            return "";
        }
    }
    for (let t = 0; 1e5 > t; t++) thing(0), thing(2), thing(6);
  • bounce patttern

     
    function bounce(x) 
    {
       if (x === 0) return "0";
       if (x === 1) return "1";
       if (x === 2) return "2";
       if (x === 3) return "3";
       
       return ""
    }
    for (let t = 0; 1e5 > t; t++) bounce(0), bounce(2), bounce(6);
  • ternary

     
    function bounce(x) {
        return 0 === x ? "0" : 1 === x ? "1" : 2 === x ? "2" : 3 === x ? "3" : "";
    }
    for (let t = 0; 1e5 > t; t++) bounce(0), bounce(2), bounce(6);
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    switch case
    bounce patttern
    ternary

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: one year ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36
Chrome 119 on Windows
View result in a separate tab
Test name Executions per second
switch case 20315.4 Ops/sec
bounce patttern 20222.3 Ops/sec
ternary 20511.1 Ops/sec