Multiply by 0.5 rather than divide by 2
c
Solution
It's true that some (if not most) processors can multiply faster than performing a division operation, but, it's like the myth of `++i` being faster than `i++` in a for loop. Yes, it once was, but nowadays, compilers are smart enough to optimize all those things for you, so you should not care about this anymore.
And about bit-shifting, it once was faster to shift `<< 2` than to multiply by 4, but those days are over as most processors can multiply in one clock cycle, just like a shift operation.
A great example of this was the calculation of the pixel address in VGA `320x240` mode. They all did this:
address = x + (y << 8) + (y << 6)
to multiply y with 320. On modern processors, this can be slower than just doing:
address = x + y * 320;
So, just write what you think and the compiler will do the rest :)
Problem
While I was reading tips in C, I have seen this tip here http://www.cprogramming.com/tips/tip/multiply-rather-than-divide but I am not sure. I was told both multiply and divide are slower and time consuming and requires many cycles. and I have seen people often use `i << 2` instead of `i x 4` since shifting is faster. Is it a good tip using `x0.5 or /2` ? or however modern compilers do optimize it in a better way?