What is the effect of ordering if…else if statements by probability?
问题 Specifically, if I have a series of if ... else if statements, and I somehow know beforehand the relative probability that each statement will evaluate to true , how much difference in execution time does it make to sort them in order of probability? For example, should I prefer this: if (highly_likely) //do something else if (somewhat_likely) //do something else if (unlikely) //do something to this?: if (unlikely) //do something else if (somewhat_likely) //do something else if (highly_likely