Run details:
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
Windows
Desktop
one year ago
Test name Executions per second
Switch 957295744.0 Ops/sec
Map 1881327.2 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;
      }
  • Map

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