Possible Duplicate:
If vs. Switch Speed
I will use c++ as an example, but the question I am asking isn't towards a particular language. I mean in general. Which one is better for performance? This isn't a question about programming styles.
Of course, in certain circumstances the switch statement may be easier to use than an if statement. But if you wanted MAXIMUM performance. Like if there was thousands of lines of code and more than 10 switch statements that COULD be replaced with if statements, which one would cause better performance?
Example:
if(x == 6){
do this
}
if(x == 67){
do this * 2
}
if(x == 9000){
do this * 3
}
vs
//Please forgive me if the syntax for the switch statement is wrong, I haven't use one in any programming language for a long time
Switch(x){
case 6:
do this
case 67:
do this * 2
case 9000:
do this * 3
}
So how does this differ in performance? When you answer, make sure your answer includes the programming language you are referring to. If in java, state that you are talking about java and not c++, javascript, whatever language you chose to answer my question.