Local tests pass and I get a performance boost of ~6% for double to string conversion.
It's difficult to pinpoint exactly what makes the performance better. Here are some clues. First I've removed the old loop (basically, I've unrolled it)
while (output2 >= 10000) {
This suggests (very broadly speaking) a complexity O(N) (where N is the input's number of digits). My code, instead, in each "iteration" compares what used to be output2 against 10⁸, 10⁴, 10² and 10¹ which indicates a complexity O(log(N)). Also, I don't calculate the number of digits beforehand. (See the comment about decimalLength17 is no longer called.)
Also, I've reduced the number of pointer/array arithmetic operations and the writing is done in a single direction from smaller to larger addresses.
If all that is fine, I guess a similar work could be done for the float to string conversion.
Local tests pass and I get a performance boost of ~6% for double to string conversion.
It's difficult to pinpoint exactly what makes the performance better. Here are some clues. First I've removed the old loop (basically, I've unrolled it)
This suggests (very broadly speaking) a complexity O(N) (where N is the input's number of digits). My code, instead, in each "iteration" compares what used to be
output2
against 10⁸, 10⁴, 10² and 10¹ which indicates a complexity O(log(N)). Also, I don't calculate the number of digits beforehand. (See the comment aboutdecimalLength17
is no longer called.)Also, I've reduced the number of pointer/array arithmetic operations and the writing is done in a single direction from smaller to larger addresses.
If all that is fine, I guess a similar work could be done for the float to string conversion.