summaryrefslogtreecommitdiffhomepage
path: root/compat/timer.hpp
diff options
context:
space:
mode:
authorStanisław Halik <sthalik@misaki.pl>2017-05-14 16:22:09 +0200
committerGitHub <noreply@github.com>2017-05-14 16:22:09 +0200
commit5c23666b58bb1dd4aea15c0d62a2f716d5be7f52 (patch)
treee6497e9b55c073be209ec673ef05e62bf57a2c8f /compat/timer.hpp
parent4701dd3b0c8323a11cf7d5ad09c579a9864a41bd (diff)
parentc392181211b245e74292424500265323c960c1aa (diff)
Merge branch 'unstable' into unstable
Diffstat (limited to 'compat/timer.hpp')
-rw-r--r--compat/timer.hpp18
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;
};
-
-