Let say I have a switch statement as below
switch(alphabet) {
case "f":
//do something
break;
case "c":
//do something
break;
case "a":
//do something
break;
case "e":
//do something
break;
}
Now suppose I know that the frequency of having Alphabet
e is highest followed by a, c and f respectively. So, I just restructured the case
statement order and made them as follows:
switch(alphabet) {
case "e":
//do something
break;
case "a":
//do something
break;
case "c":
//do something
break;
case "f":
//do something
break;
}
Will the second switch
statement be faster than the first switch
statement? If yes and if in my program I need to call this switch
statement say many times, will that be a substantial improvement? Or if not in any how can I use my frequency knowledge to improve the performance?