Script Preparation code:
x
 
const use = (a, fn) => fn(a);
const isFunc = (v) => typeof v === 'function';
const isDefined = v => v !== undefined && v !== null;
const switchEnum = (e, handlers) => use(handlers[e] || handlers.else, fn => isFunc(fn) ? fn(e) : e);
function normal(inp) {
  switch (inp) {
    case "today":
      return 1;
    case "tomorrow":
      return 2;
    case "yesterday":
      return -1;
    default:
      return 0; 
  }
};
function funcccy(inp) {
 return switchEnum(inp, {
   "today": () => 1,
   "tomorrow": () => 2,
   "yesterday": () => -1,
   "else": () => 0,
  });
}
Tests:
  • Vanilla Switch

     
    normal('today');
    normal('yesterday');
    normal('tomorrow');
  • Switch Fn style

     
    funcccy('today');
    funcccy('yesterday');
    funcccy('tomorrow');
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Vanilla Switch
    Switch Fn style

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: one year ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36
Chrome 122 on Mac OS X 10.15.7
View result in a separate tab
Test name Executions per second
Vanilla Switch 10824798.0 Ops/sec
Switch Fn style 6031819.0 Ops/sec