For one of my own small project, I needed a fast string to float conversion function that worked well with stringviews. I had read about the new C++17 function: std::from_chars_result from_chars(const char* first, const char* last, float& value, std::chars_format fmt = std::chars_format::general)

It worked well, but ofc I was wondering about the speed of it. So I tried to make my own version, and managed to make a function that is ~2x to 5x faster.

To be clear; I have only written one for floats, and I don’t care about the fmt argument. One for doubles should be very similar. And integers would be a lot easier, so I might create these, before I share the code.

And now when I wanted to benchmark it properly using different compilers, I find out that the float version isn’t even supported yet for most compilers. :/ So, this is my own comparisons, using Visual Studio 2019 (16.8.5).

Simply converting these string 10’000’000 times in a row. Time in microseconds.

string to convert time std::from_chars time my from_chars
111e-2711139
1.1100720181
-1234567890466248



… I’ll try to make a tiny github thing out of it. Will update post when I do.