I have encountered problem of converting float to string where to_string is too slow for me as my data might involves few millions floats.
I already have so
Here are some of the fastest algorithms for converting floating point numbers into decimal string representation:
At the time of writing Dragonbox is the fastest of these methods, followed by Schubfach, then a variation of Grisu called Grisu-Exact (not to be confused with Grisu2 and Grisu3) and then Ryū:
An implementation of Dragonbox is available here. It is also included in the {fmt} library integrated into a high-level formatting API. For maximum performance you can use format_to with a stack-allocated buffer, for example:
fmt::memory_buffer buf;
fmt::format_to(buf, "{}", 4.2);
// buf.data() returns a pointer to the formatted data & buf.size() gives the size