MCPcopy Create free account
hub / github.com/InteractiveComputerGraphics/SPlisHSPlasH / getFormattedDuration

Function getFormattedDuration

extern/Catch2/catch.hpp:15776–15792  ·  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

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

Callers 1

sectionEndedMethod · 0.85

Calls 1

stringFunction · 0.85

Tested by

no test coverage detected