Is case after case in a switch efficient?
Posted
by
RandomGuy
on Programmers
See other posts from Programmers
or by RandomGuy
Published on 2012-06-23T18:53:35Z
Indexed on
2012/06/23
21:24 UTC
Read the original article
Hit count: 382
Just a random question regarding switch case efficiency in case after case; is the following code (assume pseudo code):
function bool isValid(String myString){
switch(myString){
case "stringA":
case "stringB":
case "stringC":
return true;
default:
return false;
}
more efficient than this:
function bool isValid(String myString){
switch(myString){
case "stringA":
return true;
case "stringB":
return true;
case "stringC":
return true;
default:
return false;
}
Or is the performance equal? I'm not thinking in a specific language but if needed let's assume it's Java or C (for this case would be needed to use chars instead of strings).
© Programmers or respective owner