Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36
Chrome 73
Windows
Desktop
5 years ago
Test name Executions per second
Switch 1 case 1715021.1 Ops/sec
If-else 1 case 1853480.1 Ops/sec
Object 1 prop 1847675.1 Ops/sec
Switch 2 cases 1671411.2 Ops/sec
If-else 2 cases 1759571.6 Ops/sec
Object 2 props 1836061.0 Ops/sec
Switch 4 cases 1619488.9 Ops/sec
If-else 4 cases 1705268.1 Ops/sec
Object 4 props 1823828.2 Ops/sec
Switch 10 cases 1492248.4 Ops/sec
If-else 10 cases 1563881.1 Ops/sec
Object 10 props 1735542.8 Ops/sec
Switch 50 cases 961001.7 Ops/sec
If-else 50 cases 1104625.5 Ops/sec
Object 50 props 1817710.6 Ops/sec
Switch 1k cases 120568.0 Ops/sec
If-else 1k cases 124806.3 Ops/sec
Object 1k props 1853083.4 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


;