Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36
Chrome 90
Windows
Desktop
3 years ago
Test name Executions per second
Switch 1 case 4354987.5 Ops/sec
If-else 1 case 3835972.0 Ops/sec
Object 1 prop 3872275.2 Ops/sec
Switch 2 cases 3924399.5 Ops/sec
If-else 2 cases 3958182.2 Ops/sec
Object 2 props 3842624.5 Ops/sec
Switch 4 cases 3959693.2 Ops/sec
If-else 4 cases 4087019.0 Ops/sec
Object 4 props 4318251.0 Ops/sec
Switch 10 cases 3854731.2 Ops/sec
If-else 10 cases 3823017.0 Ops/sec
Object 10 props 4304796.5 Ops/sec
Switch 50 cases 3184009.0 Ops/sec
If-else 50 cases 3284862.5 Ops/sec
Object 50 props 4310073.0 Ops/sec
Switch 1k cases 331645.8 Ops/sec
If-else 1k cases 323273.7 Ops/sec
Object 1k props 4082275.0 Ops/sec
Script Preparation code:
Tests:
  • Switch 1 case

  • Switch 1k cases

  • Object 50 props

  • If-else 50 cases

  • Switch 50 cases

  • Object 10 props

  • If-else 10 cases

  • Switch 10 cases

  • Object 4 props

  • If-else 4 cases

  • Switch 4 cases

  • Object 2 props

  • If-else 2 cases

  • Switch 2 cases

  • Object 1 prop

  • If-else 1 case

  • If-else 1k cases

  • Object 1k props


;