I was recently making a program which needed to check the number of digits in a number inputted by the user. As a result I made the following code:
int x;
Given a very pipelined cpu with conditional moves, this example may be quicker:
if (x > 100000000) { x /= 100000000; count += 8; }
if (x > 10000) { x /= 10000; count += 4; }
if (x > 100) { x /= 100; count += 2; }
if (x > 10) { x /= 10; count += 1; }
as it is fully unrolled. A good compiler may also unroll the while loop to a maximum of 10 iterations though.