MCPcopy Create free account
hub / github.com/apache/trafficserver / getFormattedDuration

Function getFormattedDuration

lib/catch2/catch.hpp:15774–15790  ·  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

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 ) {

Callers 1

sectionEndedMethod · 0.85

Calls 1

stringClass · 0.85

Tested by

no test coverage detected