Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36
Chrome 118
Windows
Desktop
one year ago
Test name Executions per second
switch 12714865.0 Ops/sec
if/else if 2828823.0 Ops/sec
Script Preparation code:
AخA
 
var test = 'test'
Tests:
  • switch

     
    switch(test) {
      case 'test1':
        return true;
      case 'test2':
        return true;
      case 'test3':
        return true;
      case 'test4':
        return true;
      case 'test5':
        return true;
      default:
        return true;
    }
  • if/else if

     
    if (test === 'test1') {
      return true;
    } else if (test === 'test2') {
      return true;
    } else if (test === 'test3') {
      return true;
    } else if (test === 'test4') {
      return true;
    } else if (test === 'test5') {
      return true;
    }