4 ms·
After a little more spelunking, it seems that this particular case was possible to optimize. While you can set the thousands separator for integers in C++ via l
by slavik81 6y ago
After a little more spelunking, it seems that this particular case was possible to optimize. While you can set the thousands separator for integers in C++ via locales, it only applies to iostreams and not to sprintf. You can also set it for sprintf in POSIX, but it doesn't apply to integers unless you opt-in via the format specifier.
So, there is no applicable locale information needed for integer formatting with std::to_string, and GCC began to replace the naive sprintf-based implementation with one based on std::to_chars in 2017: https://gcc.gnu.org/legacy-ml/gcc-patches/2017-05/msg02103.html https://gcc.gnu.org/legacy-ml/gcc-patches/2017-05/msg02103.h...
The problems I previously mentioned would apply if that were a float, though, and I would still recommend using std::to_chars just so you don't have to think about it.