I am thinking on how to implement the conversion of an integer (4byte, unsigned) to string with SSE instructions. The usual routine is to divide the number and store it in a loc
This post compares several methods of integer to string conversion aka itoa. The fastest method reported there is fmt::FormatInt
from the fmt library which is about 8 times faster than sprintf
/std::stringstream
and 5 times faster than the naive ltoa
/itoa
implementation (the actual numbers may of course vary depending on platform).
Unlike most other methods fmt::FormatInt
does one pass over the digits. It also minimizes the number of integer divisions using the idea from Alexandrescu's talk Three Optimization Tips for C++. The implementation is available here.
This is of course if C++ is an option and you are not restricted by the itoa
's API.
Disclaimer: I'm the author of this method and the fmt library.