MCPcopy Create free account
hub / github.com/CodingGay/BlackDex / getFormattedDuration

Function getFormattedDuration

Bcore/src/main/cpp/Dobby/tests/catch.hpp:11164–11180  ·  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

11162// Because formatting using c++ streams is stateful, drop down to C is required
11163// Alternatively we could use stringstream, but its performance is... not good.
11164std::string getFormattedDuration(double duration) {
11165 // Max exponent + 1 is required to represent the whole part
11166 // + 1 for decimal point
11167 // + 3 for the 3 decimal places
11168 // + 1 for null terminator
11169 const std::size_t maxDoubleSize = DBL_MAX_10_EXP + 1 + 1 + 3 + 1;
11170 char buffer[maxDoubleSize];
11171
11172 // Save previous errno, to prevent sprintf from overwriting it
11173 ErrnoGuard guard;
11174#ifdef _MSC_VER
11175 sprintf_s(buffer, "%.3f", duration);
11176#else
11177 sprintf(buffer, "%.3f", duration);
11178#endif
11179 return std::string(buffer);
11180}
11181
11182TestEventListenerBase::TestEventListenerBase(ReporterConfig const &_config) : StreamingReporterBase(_config) {
11183}

Callers 1

sectionEndedMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected