Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Safari/605.1.15
Safari 13
Mac OS X 10.15
Desktop
4 years ago
Test name Executions per second
Switch 1 case 2768555.5 Ops/sec
If-else 1 case 2773617.5 Ops/sec
Object 1 prop 2549698.2 Ops/sec
Switch 2 cases 2729300.5 Ops/sec
If-else 2 cases 2737304.8 Ops/sec
Object 2 props 2550204.8 Ops/sec
Switch 4 cases 2781987.2 Ops/sec
If-else 4 cases 2695845.8 Ops/sec
Object 4 props 2536384.2 Ops/sec
Switch 10 cases 2762118.0 Ops/sec
If-else 10 cases 2449068.8 Ops/sec
Object 10 props 2475656.5 Ops/sec
Switch 50 cases 2752339.2 Ops/sec
If-else 50 cases 2107359.8 Ops/sec
Object 50 props 2514209.0 Ops/sec
Switch 1k cases 2672230.8 Ops/sec
If-else 1k cases 115213.6 Ops/sec
Object 1k props 2550471.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


;