0

I use else if statements a lot in my programming and not a lot of switch case statements. I know at one point switch case statements become more efficient than else if statements so I was wondering at which point that happens.
Ex: 3 operations, 5 operations, 20 operations.

sazzy4o
  • 3,073
  • 6
  • 34
  • 62
  • 2
    It largely depends on what you are using for the `case` in the switch: integers, enum values, strings, ...? – hotzst Nov 22 '15 at 19:32
  • 3
    Just to keep this in perspective: we are talking about nanoseconds or at most a couple of microseconds in performance difference. There are few scenarios where this matters as much as code readability. 99.9% of the time there are more relevant ways to improve algorithms. My two cents. – Phil Freihofner Nov 22 '15 at 19:35
  • 1
    It's the point at which `switch` becomes easier to read which really matters. Unless you mean millions of times per second, it is unlikely to matter too much. – Peter Lawrey Nov 22 '15 at 19:39

0 Answers0