Because formatting using c++ streams is stateful, drop down to C is required Alternatively we could use stringstream, but its performance is... not good.
| 11162 | // Because formatting using c++ streams is stateful, drop down to C is required |
| 11163 | // Alternatively we could use stringstream, but its performance is... not good. |
| 11164 | std::string getFormattedDuration(double duration) { |
| 11165 | // Max exponent + 1 is required to represent the whole part |
| 11166 | // + 1 for decimal point |
| 11167 | // + 3 for the 3 decimal places |
| 11168 | // + 1 for null terminator |
| 11169 | const std::size_t maxDoubleSize = DBL_MAX_10_EXP + 1 + 1 + 3 + 1; |
| 11170 | char buffer[maxDoubleSize]; |
| 11171 | |
| 11172 | // Save previous errno, to prevent sprintf from overwriting it |
| 11173 | ErrnoGuard guard; |
| 11174 | #ifdef _MSC_VER |
| 11175 | sprintf_s(buffer, "%.3f", duration); |
| 11176 | #else |
| 11177 | sprintf(buffer, "%.3f", duration); |
| 11178 | #endif |
| 11179 | return std::string(buffer); |
| 11180 | } |
| 11181 | |
| 11182 | TestEventListenerBase::TestEventListenerBase(ReporterConfig const &_config) : StreamingReporterBase(_config) { |
| 11183 | } |