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*10into the appropriate bit-shift operations if it believes they would be faster. It may not be able to do the opposite. So always writeu*10if you meanu*10, unless you know you’re working with a bad compiler.