Because formatting using c++ streams is stateful, drop down to C is required Alternatively we could use stringstream, but its performance is... not good.
| 12769 | // Because formatting using c++ streams is stateful, drop down to C is required |
| 12770 | // Alternatively we could use stringstream, but its performance is... not good. |
| 12771 | std::string getFormattedDuration( double duration ) { |
| 12772 | // Max exponent + 1 is required to represent the whole part |
| 12773 | // + 1 for decimal point |
| 12774 | // + 3 for the 3 decimal places |
| 12775 | // + 1 for null terminator |
| 12776 | const std::size_t maxDoubleSize = DBL_MAX_10_EXP + 1 + 1 + 3 + 1; |
| 12777 | char buffer[maxDoubleSize]; |
| 12778 | |
| 12779 | // Save previous errno, to prevent sprintf from overwriting it |
| 12780 | ErrnoGuard guard; |
| 12781 | #ifdef _MSC_VER |
| 12782 | sprintf_s(buffer, "%.3f", duration); |
| 12783 | #else |
| 12784 | sprintf(buffer, "%.3f", duration); |
| 12785 | #endif |
| 12786 | return std::string(buffer); |
| 12787 | } |
| 12788 | |
| 12789 | TestEventListenerBase::TestEventListenerBase(ReporterConfig const & _config) |
| 12790 | :StreamingReporterBase(_config) {} |