Which is faster? switch or if-else ?
Thursday, February 7th, 2008Every time I have a state where I need to use switch\if-else-irritation I can’t quite figure our which is the better choice. I am pretty sure there is no one answer to this question, but i did stumble upon an interesting test:
This test shows that, as i suspected all along(Mu-ha-ha), the switch is faster, and in a significant way.
I’m sure that some people will still state if-else is more readable, but personally, i do not agree with that.
What do you choose when you face this issue? if-else/switch? or an entirely different mechanism?
Have a good one, =]
Nadav