for long numbers:
original = 1408/24 = ~59us / digit to print
"tom" = 480/24 = ~20 us/digit to print (33%)
"paul" = 224/24 = ~ 9.5uS /digit to print (16%)
A quick arbitrary float test (same prog as above, slightly different printnumber)
Serial.println(10737.41824, 4);
Serial.println(1.01819584, 4);
Serial.println(107.37, 2);
original printnumber
testing
10737.4179
1.0182
107.37
Time=2144
done
divmod10 printnumber
testing
10737.4179
1.0182
107.37
Time=1472
done
so for floats there is also serious gain ~30% gain
(note this gain is only due to the integral part, the remainder part is a loop using a float mul per digit
// Extract digits from the remainder one at a time
while (digits-- > 0)
{
remainder *= 10.0;
int toPrint = int(remainder);
n += print(toPrint);
remainder -= toPrint;
}
this can be optimized to something like:
// Extract digits from the remainder one at a time
long t = 1;
while (digits-- > 0) t *= 10;
remainder *= t;
n += print(long(remainder));
a quick test exposes the flaw in the proposed code but also indicates there is room for improvement.
testing
10737.4179
1.182 <<<<<< FAIL !!!
107.37
Time=1152 <<< (another 25%)
done