What is the effect of ordering if…else if statements by probability?

后端 未结 10 1798
花落未央
花落未央 2020-12-07 13:39

Specifically, if I have a series of if...else if statements, and I somehow know beforehand the relative probability that each statement will evalua

10条回答
  •  情歌与酒
    2020-12-07 13:54

    Put them in whatever logical order you like. Sure, the branch may be slower, but branching should not be the majority of work your computer is doing.

    If you are working on a performance critical portion of code, then certainly use logical order, profile guided optimization and other techniques, but for general code, I think its really more of a stylistic choice.

提交回复
热议问题