JiiPee
2014-11-01 22:02:34 UTC
I wonder how C++ standard library has not implemented a very fast
integer-to-string conversion function. They have sprintf, snprintf,
stringstream and to_string.
From this site:
http://zverovich.net/2013/09/07/integer-to-string-conversion-in-cplusplus.html
we can see that sprintf is the fastest one of those.
But then I googled and found from this site:
http://stackoverflow.com/questions/4351371/c-performance-challenge-integer-to-stdstring-conversion
a very fast version, done by somebody. I run tests (using a integers
from 0 to 1294967295 by step 60 and converted all of them to strings. I
also used the sixth item from the result: cU += str2[6]; inside the loop
and then printed it at the end so that the compiler would not optimize
things out).
Results: the user made conversion function from the site was about 130
times faster than sprintf (and thus would be about 200 times faster than
to_string ).
How is it possible there is no fast std version? This is sometimes an
important function, for example when parsing a very large text and
checking integers from it.
Not really complaining but want to start a discussion about this: why
std sometimes does not make fast functions/classes?
For me, I already added that new fast conversion function to my
toolset... I rather use it than library versions. btw if somebody wants
my fast function please ask, I can give it then. Also, if somebody knows
faster way to convert, am ready to test it against this! I have a test
platform ready.
integer-to-string conversion function. They have sprintf, snprintf,
stringstream and to_string.
From this site:
http://zverovich.net/2013/09/07/integer-to-string-conversion-in-cplusplus.html
we can see that sprintf is the fastest one of those.
But then I googled and found from this site:
http://stackoverflow.com/questions/4351371/c-performance-challenge-integer-to-stdstring-conversion
a very fast version, done by somebody. I run tests (using a integers
from 0 to 1294967295 by step 60 and converted all of them to strings. I
also used the sixth item from the result: cU += str2[6]; inside the loop
and then printed it at the end so that the compiler would not optimize
things out).
Results: the user made conversion function from the site was about 130
times faster than sprintf (and thus would be about 200 times faster than
to_string ).
How is it possible there is no fast std version? This is sometimes an
important function, for example when parsing a very large text and
checking integers from it.
Not really complaining but want to start a discussion about this: why
std sometimes does not make fast functions/classes?
For me, I already added that new fast conversion function to my
toolset... I rather use it than library versions. btw if somebody wants
my fast function please ask, I can give it then. Also, if somebody knows
faster way to convert, am ready to test it against this! I have a test
platform ready.