Script Preparation code:
x
 
window.map = {
    "first": "1",
    "second": "2",
    "third": "3",
    "forth": "4",
    "fifth": "5",
    "sixth": "6",
    "seventh": "7",
    "eighth": "8",
    "nineth": "9",
    "tenth": 10
};
window.values = ["first", "second", "third", "forth", "fifth", "sixth", "seventh", "eighth", "nineth", "tenth"];
Tests:
  • Switch Case

     
    const { map, values } = window;
    function resolve(value) {
      switch (value) {
        case "first":
          return "1";
        case "second":
          return "2";
        case "third":
          return "3";
        case "forth":
          return "4";
        case "five":
          return "5";
        case "sixth":
          return "6";
        case "seventh":
          return "7";
        case "eighth":
          return "8";
        case "nineth":
          return "9";
        case "tenth":
          return "10";
      }
    }
    for (let i=0; i < values.length; i++) {
      resolve(values[i]);
    }  
  • Map

     
    const { map, values } = window;
    function resolve(value) {
      return map[value];
    }
    for (let i=0; i < values.length; i++) {
      resolve(values[i]);
    }  
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Switch Case
    Map

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 2 years ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36
Chrome 109 on Windows
View result in a separate tab
Test name Executions per second
Switch Case 11187048.0 Ops/sec
Map 6873633.5 Ops/sec