Avoid if/ else within loop

Yes, this post is about the most basic concept that using if/ else should be avoided within a loop as much as possible. Optimizing code is always important and when it’s about performance then the basic efficiency rules should be followed at first. Practically there are many situations when a loop iterates over large data set e.g. 10m; there may be differently required computation in the same loop- but if possible the loop should maintain branch prediction; avoid unnecessary if/ else.

Following simple rules lead to performance advantage certainly. Branch prediction is a simple concept to optimize a loop-
Continue reading