mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-26 07:16:10 +01:00
Timer resolution is now nanoseconds
This commit is contained in:
parent
c7028f7bc7
commit
39d37d9f34
@ -12,8 +12,8 @@
|
|||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
auto getCurrentMicrosecondsSinceEpoch() -> uint64_t {
|
auto getCurrentNanosecondsSinceEpoch() -> uint64_t {
|
||||||
return std::chrono::duration_cast<std::chrono::microseconds>( std::chrono::high_resolution_clock::now().time_since_epoch() ).count();
|
return std::chrono::duration_cast<std::chrono::nanoseconds>( std::chrono::high_resolution_clock::now().time_since_epoch() ).count();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Catch
|
} // namespace Catch
|
||||||
|
@ -12,16 +12,19 @@
|
|||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
auto getCurrentMicrosecondsSinceEpoch() -> uint64_t;
|
auto getCurrentNanosecondsSinceEpoch() -> uint64_t;
|
||||||
|
|
||||||
class Timer {
|
class Timer {
|
||||||
uint64_t m_microSeconds = 0;
|
uint64_t m_nanoseconds = 0;
|
||||||
public:
|
public:
|
||||||
void start() {
|
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 {
|
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 {
|
auto getElapsedMilliseconds() const -> unsigned int {
|
||||||
return static_cast<unsigned int>(getElapsedMicroseconds()/1000);
|
return static_cast<unsigned int>(getElapsedMicroseconds()/1000);
|
||||||
|
Loading…
Reference in New Issue
Block a user