code optimization; switch versus if's
- by KaiserJohaan
Hello,
I have a question about whether to use 'case' or 'ifs' in a function that gets called quite alot.
Here's the following as it is now, in 'ifs'; the code is self-explanatory:
int identifyMsg(char* textbuff) {
if (!strcmp(textbuff,"text")) {
return 1;
}
if (!strcmp(textbuff,"name")) {
return 2;
}
if (!strcmp(textbuff,"list")) {
return 3;
}
if (!strcmp(textbuff,"remv")) {
return 4;
}
if (!strcmp(textbuff,"ipad")) {
return 5;
}
if (!strcmp(textbuff,"iprm")) {
return 6;
}
return 0;
}
My question is: Would a switch perform better? I know if using ifs, I can place the most likely options at the top.