for loops are basic language constructs in many languages. One of the first things to look at when optimizing code is loops, as they do considerable amounts of work (like going through a very large amount of data) in very little code.
If you use a for loop, but you don’t really care about the order in which the loop is executed – to be more precise, if you can afford reversing the loop – you can save quite some time. By reversing the loop, I mean that instead of giving the index values from 0 to 10, for example, you go from 10 downward to zero. This doesn’t seem like a big change, but when carefully implemented, this can easily improve the performance of your for loops.
Continue reading Optimizing for Loops: Reverse Loops