MCPcopy Create free account
hub / github.com/apache/qpid-proton / getFormattedDuration

Function getFormattedDuration

tests/include/catch.hpp:15778–15794  ·  view source on GitHub ↗

Because formatting using c++ streams is stateful, drop down to C is required Alternatively we could use stringstream, but its performance is... not good.

Source from the content-addressed store, hash-verified

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

Callers 1

sectionEndedMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected