Friday, July 29, 2011

Some Tricks about Optimizing Branches

You should be cautious when using branches in your code. Sometimes the performance could be hurt.
while (++i > count)
The above code may generate complex machine code. It is much better to let the compiler to generate code that utilizes the processors compare instructions in an efficient way. This means creating loops that terminates when a compare value is zero, which is as follow:
while (count--)
The following code is also not good:
while (count-=2)

No comments:

Post a Comment