Because formatting using c++ streams is stateful, drop down to C is required Alternatively we could use stringstream, but its performance is... not good.
| 15772 | // Because formatting using c++ streams is stateful, drop down to C is required |
| 15773 | // Alternatively we could use stringstream, but its performance is... not good. |
| 15774 | std::string getFormattedDuration( double duration ) { |
| 15775 | // Max exponent + 1 is required to represent the whole part |
| 15776 | // + 1 for decimal point |
| 15777 | // + 3 for the 3 decimal places |
| 15778 | // + 1 for null terminator |
| 15779 | const std::size_t maxDoubleSize = DBL_MAX_10_EXP + 1 + 1 + 3 + 1; |
| 15780 | char buffer[maxDoubleSize]; |
| 15781 | |
| 15782 | // Save previous errno, to prevent sprintf from overwriting it |
| 15783 | ErrnoGuard guard; |
| 15784 | #ifdef _MSC_VER |
| 15785 | sprintf_s(buffer, "%.3f", duration); |
| 15786 | #else |
| 15787 | std::sprintf(buffer, "%.3f", duration); |
| 15788 | #endif |
| 15789 | return std::string(buffer); |
| 15790 | } |
| 15791 | |
| 15792 | bool shouldShowDuration( IConfig const& config, double duration ) { |
| 15793 | if ( config.showDurations() == ShowDurations::Always ) { |