DEV Community

Discussion on: I've never become overly convinced that switch statements are that much cleaner than `if else if else if else if else`

gazzonyx profile image
Scott Lovenberg

Switch statement runtime : O(1)
If/Else : O(n)

If your operating system drivers used if/else for polling/events, your network card would be running at a fraction of the speed it does. Sometimes performance matters. The original Linux scheduler was O(log n) which was replaced with two linked lists for a O(1) runtime since the log n scheduler was deemed too slow for process scheduling.