Is the first opeartion faster than the second one ?
u+= (u << 3) + (u << 1) //first operation
u+= u*10 //second operation
Basically both of them does the same thing that is u= u+(10*u)
But i came to knew that first operation is faster than second .
Does the cpu time when operation + different from * . Is multiplication by 10
actually equivalent to 10 addition operations being performed ?
It depends on the capabilities of the underlying CPU, and of the compiler.
Any decent compiler should optimise u*10
into the appropriate bit-shift operations if it believes they would be faster. It may not be able to do the opposite. So always write u*10
if you mean u*10
, unless you know you're working with a bad compiler.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With