Because formatting using c++ streams is stateful, drop down to C is required Alternatively we could use stringstream, but its performance is... not good.
| 11251 | // Because formatting using c++ streams is stateful, drop down to C is required |
| 11252 | // Alternatively we could use stringstream, but its performance is... not good. |
| 11253 | std::string getFormattedDuration( double duration ) { |
| 11254 | // Max exponent + 1 is required to represent the whole part |
| 11255 | // + 1 for decimal point |
| 11256 | // + 3 for the 3 decimal places |
| 11257 | // + 1 for null terminator |
| 11258 | const std::size_t maxDoubleSize = DBL_MAX_10_EXP + 1 + 1 + 3 + 1; |
| 11259 | char buffer[maxDoubleSize]; |
| 11260 | |
| 11261 | // Save previous errno, to prevent sprintf from overwriting it |
| 11262 | ErrnoGuard guard; |
| 11263 | #ifdef _MSC_VER |
| 11264 | sprintf_s(buffer, "%.3f", duration); |
| 11265 | #else |
| 11266 | sprintf(buffer, "%.3f", duration); |
| 11267 | #endif |
| 11268 | return std::string(buffer); |
| 11269 | } |
| 11270 | |
| 11271 | TestEventListenerBase::TestEventListenerBase(ReporterConfig const & _config) |
| 11272 | :StreamingReporterBase(_config) {} |