Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36
Chrome 113
Windows
Desktop
one year ago
Test name Executions per second
Switch 761796352.0 Ops/sec
Map 1404946.4 Ops/sec
Tests:
  • Switch

    x
     
    const input = 10;
      switch(input) {
        case 1:
          return true;
        case 2:
          return true;
        case 3:
          return true;
        case 4:
          return true;
         case 5:
          return true;
        case 6:
          return true;
        case 7:
          return true;
        case 8:
          return true;
          case 9:
          return true;
        case 10:
          return true;
        default:
          return 11;
      }
  • Map

     
    const input = 10;
    const mapping = new Map([
      [0, true],
      [1, true],
      [2, true],
      [3, true],
      [4, true],
      [5, true],
      [6, true],
      [7, true],
      [8, true],
      [9, true],
      [10, true],
    ]);
    const foo = mapping.get(10);