determines resolution of the given clock. This is done by measuring multiple times and returning the minimum time difference.
| 2035 | |
| 2036 | // determines resolution of the given clock. This is done by measuring multiple times and returning the minimum time difference. |
| 2037 | Clock::duration calcClockResolution(size_t numEvaluations) noexcept { |
| 2038 | auto bestDuration = Clock::duration::max(); |
| 2039 | Clock::time_point tBegin; |
| 2040 | Clock::time_point tEnd; |
| 2041 | for (size_t i = 0; i < numEvaluations; ++i) { |
| 2042 | tBegin = Clock::now(); |
| 2043 | do { |
| 2044 | tEnd = Clock::now(); |
| 2045 | } while (tBegin == tEnd); |
| 2046 | bestDuration = (std::min)(bestDuration, tEnd - tBegin); |
| 2047 | } |
| 2048 | return bestDuration; |
| 2049 | } |
| 2050 | |
| 2051 | // Calculates clock resolution once, and remembers the result |
| 2052 | Clock::duration clockResolution() noexcept { |