While parsing xml, I discovered that converting a textual floating point value back to its binary form was expensive. Here are the results of various conversion solutions. Test run on Windows7/x64, HP xw8600 dual quad core Intel Xeon e5440 @ 2.83Ghz, using Visual Studio 2013 update 4.
Test | Seconds | Ratio | Seconds | Ratio |
---|---|---|---|---|
VS2013/x86 | VS2013/x64 | |||
AToF | 0.156 | 1.00 | 0.140 | 1.00 |
atof | 0.249 | 1.60 | 0.234 | 1.67 |
strtod | 0.250 | 1.60 | 0.234 | 1.67 |
scanf | 0.468 | 3.00 | 0.406 | 2.90 |
strStream | 5.990 | 38.40 | 4.789 | 34.21 |
stringStream | 6.085 | 39.01 | 4.930 | 35.21 |
AToF is a hand written version of the standard atof(). I found the code on the web at:
The AToF source code is included in the zip file below.
I am assuming the default atof() and strtod() are slower because they deal with language/locality issues.
StringStream is the slowest way to convert a string back to its binary form.
I created a similar test in the reverse direction and here are the results:
Ratio is elapsed seconds divided by fcvt time.
Release VS2013 on HP xw8600 Xeon E5440 2.83Ghz
Test | Seconds | Ratio | Seconds | Ratio |
---|---|---|---|---|
VS2013/x86 | VS2013/x64 | |||
fcvt | 0.608 | 1.00 | 0.546 | 1.00 |
sprintf | 0.858 | 1.41 | 0.764 | 1.40 |
gcvt | 1.217 | 2.00 | 1.092 | 2.00 |
strStream | 2.886 | 4.75 | 2.091 | 3.83 |
stringStream | 2.933 | 4.82 | 2.028 | 3.71 |
Conclusion: fcvt is fastest
Please visit home page for more programs and performance information.