diff options
| author | Phil Nash | 2018-06-12 14:09:30 +0100 |
|---|---|---|
| committer | Phil Nash | 2018-06-12 14:09:30 +0100 |
| commit | b8553d62a3a98ac9d358d20b48cf99f775291557 (patch) | |
| tree | 7657a28f7fd99132590e6b417954eb77f4a66f95 /include/internal/catch_timer.cpp | |
| parent | 504607701bd5bbe6a4dbd26709aac3e181a075e3 (diff) | |
| download | catch3-b8553d62a3a98ac9d358d20b48cf99f775291557.tar.gz | |
Moved inline functions in cpp files into anon namespaces
Diffstat (limited to 'include/internal/catch_timer.cpp')
| -rw-r--r-- | include/internal/catch_timer.cpp | 44 |
1 files changed, 23 insertions, 21 deletions
diff --git a/include/internal/catch_timer.cpp b/include/internal/catch_timer.cpp index 12c04865..d52c0085 100644 --- a/include/internal/catch_timer.cpp +++ b/include/internal/catch_timer.cpp @@ -18,34 +18,36 @@ namespace Catch { return std::chrono::duration_cast<std::chrono::nanoseconds>( std::chrono::high_resolution_clock::now().time_since_epoch() ).count(); } - inline auto estimateClockResolution() -> uint64_t { - uint64_t sum = 0; - static const uint64_t iterations = 1000000; + namespace { + auto estimateClockResolution() -> uint64_t { + uint64_t sum = 0; + static const uint64_t iterations = 1000000; - auto startTime = getCurrentNanosecondsSinceEpoch(); + auto startTime = getCurrentNanosecondsSinceEpoch(); - for( std::size_t i = 0; i < iterations; ++i ) { + for( std::size_t i = 0; i < iterations; ++i ) { - uint64_t ticks; - uint64_t baseTicks = getCurrentNanosecondsSinceEpoch(); - do { - ticks = getCurrentNanosecondsSinceEpoch(); - } while( ticks == baseTicks ); + uint64_t ticks; + uint64_t baseTicks = getCurrentNanosecondsSinceEpoch(); + do { + ticks = getCurrentNanosecondsSinceEpoch(); + } while( ticks == baseTicks ); - auto delta = ticks - baseTicks; - sum += delta; + auto delta = ticks - baseTicks; + sum += delta; - // If we have been calibrating for over 3 seconds -- the clock - // is terrible and we should move on. - // TBD: How to signal that the measured resolution is probably wrong? - if (ticks > startTime + 3 * nanosecondsInSecond) { - return sum / i; + // If we have been calibrating for over 3 seconds -- the clock + // is terrible and we should move on. + // TBD: How to signal that the measured resolution is probably wrong? + if (ticks > startTime + 3 * nanosecondsInSecond) { + return sum / i; + } } - } - // We're just taking the mean, here. To do better we could take the std. dev and exclude outliers - // - and potentially do more iterations if there's a high variance. - return sum/iterations; + // We're just taking the mean, here. To do better we could take the std. dev and exclude outliers + // - and potentially do more iterations if there's a high variance. + return sum/iterations; + } } auto getEstimatedClockResolution() -> uint64_t { static auto s_resolution = estimateClockResolution(); |