+ 2
Switch v Else if
How is it that a Switch is 'faster' than an else if? It seems to me that if it is just typing, the difference is negligible at best.
3 ответов
+ 7
Tillman Doty, you are right, the Switch statement is just faster to type while the Else If statement has more options.
+ 3
@Tilman, neither if nor switch performance really matter, except you pass a complex expression to evaluate on each case. imo the statements executed inside a matching condition block matters more, how complex, or how computationally heavy they are.
Where it's possible I would use switch because I found it be more readable. I use "if" when I need more option for condition evaluation.
+ 1
It's more readable and easier to type, so in return it's technically faster. As far as if it executes faster or not, honestly, I've no idea? I've never tested it, but I'll do that shortly and let you know if there is any performance gain beyond the readability/typing side of it.