Script Preparation code:
AخA
 
var animal = "dog"
Tests:
  • Switch

    x
     
    function test(animal) {
      switch(animal){
       case 'cat': return 'Kitten'
       case 'cattle': return 'Calf'
       case 'cheetah': return 'Cub'
       case 'micio': return 'Ciccio'
       case 'liro': return 'Piro'
       case 'gnappo': return 'Guappo'
       case '1': return '1'
       case '2': return '2'
       case '3': return '3'
       case '4': return '4'
       case '5': return '5'
       case '6': return '6'
       case '7': return '7'
       case '8': return '8'
       case '9': return '9'
       case '10': return '10'
       case '11': return '11'
       case '12': return '12'
       case '13': return '13'
       case '14': return '14'
       case '15': return '15'
       case '16': return '16'
       case '17': return '17'
       case '18': return '18'
       case '19': return '19'
       case 'dog': return 'Pup'
       default: return "I don't know that"
      }
    }
    test(animal);
  • Object Literal

     
    function test(animal) {
      var babyAnimal = {
       cat:'Kitten',
       cattle:'Calf',
       cheetah:'Cub',
        micio: 'Ciccio',
        liro: 'Piro',
        gnappo: 'Guappo',
        '1': '1',
        '2': '2',
        '3': '3',
        '4': '4',
        '5': '5',
        '6': '6',
        '7': '7',
        '8': '8',
        '9': '9',
        '10': '10',
        '11': '11',
        '12': '12',
        '13': '13',
        '14': '14',
        '15': '15',
        '16': '16',
        '17': '17',
        '18': '18',
        '19': '19',
       dog:'Pup'
      }
      return babyAnimal[animal] ?? "I don't know that"
    }
    test(animal);
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Switch
    Object Literal

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 3 years ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36
Chrome 99 on Mac OS X 10.15.7
View result in a separate tab
Test name Executions per second
Switch 24599556.0 Ops/sec
Object Literal 27230836.0 Ops/sec