mirror of
https://github.com/catchorg/Catch2.git
synced 2024-12-26 20:53:31 +01:00
Timer resolution is now nanoseconds
This commit is contained in:
parent
c7028f7bc7
commit
39d37d9f34
@ -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
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user