From c5c4f8f2682710230098156e44d9ba530bef2900 Mon Sep 17 00:00:00 2001 From: koekeishiya Date: Sat, 9 Nov 2019 13:03:33 +0100 Subject: [PATCH] .. --- src/manifest.m | 1 + src/misc/timing.h | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 src/misc/timing.h diff --git a/src/manifest.m b/src/manifest.m index 79c18333..a338bd37 100644 --- a/src/manifest.m +++ b/src/manifest.m @@ -21,6 +21,7 @@ #include #include +#include "misc/timing.h" #include "misc/macros.h" #include "misc/notify.h" #include "misc/log.h" diff --git a/src/misc/timing.h b/src/misc/timing.h new file mode 100644 index 00000000..4c2bf416 --- /dev/null +++ b/src/misc/timing.h @@ -0,0 +1,29 @@ +#include +#include + +static inline uint64_t time_clock(void) +{ + return mach_absolute_time(); +} + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" +static inline uint64_t time_elapsed_ns(uint64_t begin, uint64_t end) +{ + uint64_t elapsed = end - begin; + Nanoseconds nano = AbsoluteToNanoseconds(*(AbsoluteTime *) &elapsed); + return *(uint64_t *) &nano; +} +#pragma clang diagnostic pop + +static inline double time_elapsed_ms(uint64_t begin, uint64_t end) +{ + uint64_t ns = time_elapsed_ns(begin, end); + return (double)(ns / 1000000.0); +} + +static inline double time_elapsed_s(uint64_t begin, uint64_t end) +{ + uint64_t ns = time_elapsed_ns(begin, end); + return (double)(ns / 1000000000.0); +}