Updated: 31-Aug-2009
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 Windows XP32, HP8600 2 Xeon Quad Core, using Visual Studio 2008.
| Seconds | Ratio | Test | Results |
|---|---|---|---|
| 0.282 | 1.000 | AToF | 123456001.000 |
| 0.844 | 2.993 | atof | 123456001.000 |
| 0.891 | 3.160 | strtod | 123456001.000 |
| 1.125 | 3.989 | scanf | 123456001.282 |
| 8.000 | 28.369 | strStream | 123456001.000 |
| 9.344 | 33.135 | stringStream | 123456001.000 |
Ratio is elapsed seconds divided by AToF time.
AToF is a hand written version of the standard atof(). I found the code on the web at:
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.
Home - Please visit home page for more programs and performance information.