|  | Home | Libraries | People | FAQ | More | 
            These performance measurements are centered around default formatting
            of a single double floating
            point number using different libraries and methods. The overall execution
            times for those examples are compared below. We compare using sprintf, C++ iostreams, Boost.Format,
            and Spirit.Karma.
          
            For the full source code of the performance test please see here: double_performance.cpp.
            All the measurements have been done by executing 1e6
            iterations for each formatting type (NUMITERATIONS is set to 1e6 in the code shown below).
          
            Code used to measure the performance for sprintf:
          
char buffer[256]; for (int i = 0; i < NUMITERATIONS; ++i) { sprintf(buffer, "%f", 12345.12345); }
Code used to measure the performance for standard C++ iostreams:
std::stringstream strm; for (int i = 0; i < NUMITERATIONS; ++i) { strm.str(""); strm << 12345.12345; }
Code used to measure the performance for Boost.Format:
std::string generated; boost::format double_format("%f"); for (int i = 0; i < NUMITERATIONS; ++i) generated = boost::str(double_format % 12345.12345);
The following code shows the common definitions used by all Spirit.Karma performance measurements as listed below:
using boost::spirit::karma::double_;
Code used to measure the performance for Spirit.Karma using a plain character buffer:
char buffer[256]; for (int i = 0; i < NUMITERATIONS; ++i) { char *p = buffer; generate(p, double_, 12345.12345); *p = '\0'; }
            The following table shows the overall performance results collected while
            using different compilers. All times are in seconds measured for 1e6 iterations (platform: Windows7, Intel
            Core Duo(tm) Processor, 2.8GHz, 4GByte RAM). For a more readable comparison
            of the results see this figure.
          
Table 6. Performance comparison for a single double (all times in [s], `1e6` iterations)
| Library | gcc 4.4.0 (32 bit) | VC++ 10 (32 bit) | Intel 11.1 (32 bit) | gcc 4.4.0 (64 bit) | VC++ 10 (64 bit) | Intel 11.1 (64 bit) | 
|---|---|---|---|---|---|---|
| sprintf | 0.755 | 0.965 | 0.880 | 0.713 | 0.807 | 0.694 | 
| iostreams | 2.316 | 2.624 | 1.964 | 1.634 | 1.468 | 1.354 | 
| 3.188 | 3.737 | 2.878 | 3.217 | 2.672 | 2.011 | |
| Spirit.Karma double_ | 0.813 | 0.561 | 0.368 | 0.426 | 0.260 | 0.218 |