Timer resolution is now nanoseconds

This commit is contained in:
Phil Nash 2017-08-04 12:22:16 +01:00
parent c7028f7bc7
commit 39d37d9f34
2 changed files with 9 additions and 6 deletions

View File

@ -12,8 +12,8 @@
namespace Catch {
auto getCurrentMicrosecondsSinceEpoch() -> uint64_t {
return std::chrono::duration_cast<std::chrono::microseconds>( std::chrono::high_resolution_clock::now().time_since_epoch() ).count();
auto getCurrentNanosecondsSinceEpoch() -> uint64_t {
return std::chrono::duration_cast<std::chrono::nanoseconds>( std::chrono::high_resolution_clock::now().time_since_epoch() ).count();
}
} // namespace Catch

View File

@ -12,16 +12,19 @@
namespace Catch {
auto getCurrentMicrosecondsSinceEpoch() -> uint64_t;
auto getCurrentNanosecondsSinceEpoch() -> uint64_t;
class Timer {
uint64_t m_microSeconds = 0;
uint64_t m_nanoseconds = 0;
public:
void start() {
m_microSeconds = getCurrentMicrosecondsSinceEpoch();
m_nanoseconds = getCurrentNanosecondsSinceEpoch();
}
auto getElapsedNanoseconds() const -> unsigned int {
return static_cast<unsigned int>(getCurrentNanosecondsSinceEpoch() - m_nanoseconds);
}
auto getElapsedMicroseconds() const -> unsigned int {
return static_cast<unsigned int>(getCurrentMicrosecondsSinceEpoch() - m_microSeconds);
return static_cast<unsigned int>(getElapsedNanoseconds()/1000);
}
auto getElapsedMilliseconds() const -> unsigned int {
return static_cast<unsigned int>(getElapsedMicroseconds()/1000);