diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2017-05-12 15:40:49 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2017-05-12 15:40:49 +0200 |
commit | d160fbec0c70095b725d612458ae9ee3aa8ed526 (patch) | |
tree | 84add8f7929b33adfe33cdbe2b8588f0813812a9 /compat/timer.hpp | |
parent | ad496a028cee3e119177a3a7d9e9f4f0edb3f96c (diff) |
compat/timer: add std::chrono support
Diffstat (limited to 'compat/timer.hpp')
-rw-r--r-- | compat/timer.hpp | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/compat/timer.hpp b/compat/timer.hpp index e9efba79..58e1c7d6 100644 --- a/compat/timer.hpp +++ b/compat/timer.hpp @@ -20,7 +20,9 @@ #include <ctime> #include <tuple> -class OTR_COMPAT_EXPORT Timer +#include "time.hpp" + +class OTR_COMPAT_EXPORT Timer final { struct timespec state; long long conv_nsecs(const struct timespec& cur) const; @@ -31,16 +33,22 @@ class OTR_COMPAT_EXPORT Timer static mach_timebase_info_data_t otr_get_mach_frequency(); #endif - static void wrap_gettime(struct timespec* state); + static void gettime(struct timespec* state); + using ns = time_units::ns; public: Timer(); - void start(); + + template<typename t> + t elapsed() const + { + using namespace time_units; + return static_cast<const t&>(ns(elapsed_nsecs())); + } + long long elapsed_nsecs() const; double elapsed_usecs() const; double elapsed_ms() const; double elapsed_seconds() const; }; - - |