Made most of Timer class inline - and export getCurrentMicrosecondsSinceEpoch()

This commit is contained in:
Phil Nash 2017-08-04 12:16:05 +01:00
parent 5450de2acd
commit c7028f7bc7
2 changed files with 18 additions and 24 deletions

View File

@ -12,23 +12,8 @@
namespace Catch {
namespace {
uint64_t getCurrentMicrosecondsSinceEpoch() {
auto getCurrentMicrosecondsSinceEpoch() -> uint64_t {
return std::chrono::duration_cast<std::chrono::microseconds>( std::chrono::high_resolution_clock::now().time_since_epoch() ).count();
}
}
void Timer::start() {
m_microSeconds = getCurrentMicrosecondsSinceEpoch();
}
unsigned int Timer::getElapsedMicroseconds() const {
return static_cast<unsigned int>(getCurrentMicrosecondsSinceEpoch() - m_microSeconds);
}
unsigned int Timer::getElapsedMilliseconds() const {
return static_cast<unsigned int>(getElapsedMicroseconds()/1000);
}
double Timer::getElapsedSeconds() const {
return getElapsedMicroseconds()/1000000.0;
}
} // namespace Catch

View File

@ -11,15 +11,24 @@
#include <stdint.h>
namespace Catch {
class Timer {
public:
void start();
unsigned int getElapsedMicroseconds() const;
unsigned int getElapsedMilliseconds() const;
double getElapsedSeconds() const;
private:
auto getCurrentMicrosecondsSinceEpoch() -> uint64_t;
class Timer {
uint64_t m_microSeconds = 0;
public:
void start() {
m_microSeconds = getCurrentMicrosecondsSinceEpoch();
}
auto getElapsedMicroseconds() const -> unsigned int {
return static_cast<unsigned int>(getCurrentMicrosecondsSinceEpoch() - m_microSeconds);
}
auto getElapsedMilliseconds() const -> unsigned int {
return static_cast<unsigned int>(getElapsedMicroseconds()/1000);
}
auto getElapsedSeconds() const -> double {
return getElapsedMicroseconds()/1000000.0;
}
};
} // namespace Catch