Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36
Chrome 72
Mac OS X 10.11.6
Desktop
5 years ago
Test name Executions per second
Switch 1 case 2393006.8 Ops/sec
If-else 1 case 2661224.5 Ops/sec
Object 1 prop 2417686.0 Ops/sec
Switch 2 cases 2437910.0 Ops/sec
If-else 2 cases 2731335.2 Ops/sec
Object 2 props 2384699.8 Ops/sec
Switch 4 cases 2223353.0 Ops/sec
If-else 4 cases 2447868.2 Ops/sec
Object 4 props 2287091.5 Ops/sec
Switch 10 cases 2157545.5 Ops/sec
If-else 10 cases 2371571.2 Ops/sec
Object 10 props 2316032.8 Ops/sec
Switch 50 cases 1746336.1 Ops/sec
If-else 50 cases 1853916.2 Ops/sec
Object 50 props 2350070.8 Ops/sec
Switch 1k cases 180014.4 Ops/sec
If-else 1k cases 195264.8 Ops/sec
Object 1k props 2405912.2 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


;