diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2020-12-13 14:07:18 -0500 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2020-12-13 14:07:18 -0500 |
commit | 2146ec5f34e020e4b86e604fdf4859fc55d8f199 (patch) | |
tree | 07e2059f7c78e8f1e6e8ca70e47f38477b099e4e /time.cpp | |
parent | b36b0f8fa135beee0a50f16298692c1e076fa9b0 (diff) |
fixed NaN bug; show total time
Diffstat (limited to 'time.cpp')
-rw-r--r-- | time.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
@@ -17,6 +17,32 @@ static struct timespec time_last_modified(char const *filename) { #endif } +// get the current time. this should only really be used for +// time intervals, since there's no significance to the absolute number. +static struct timespec time_get(void) { + struct timespec ts = {}; +#if _WIN32 + FILETIME ft; + ULARGE_INTEGER bigint; + ULONGLONG t; + GetSystemTimeAsFileTime(&ft); + bigint.LowPart = ft.dwLowDateTime; + bigint.HighPart = ft.dwHighDateTime; + t = bigint.QuadPart; + ts.tv_sec = t / 10000000; + ts.tv_nsec = (t % 10000000) * 100; +#else + clock_gettime(CLOCK_MONOTONIC, &ts); +#endif + return ts; +} + +// subtract timespecs. the return value is seconds. +static double timespec_sub(struct timespec a, struct timespec b) { + return (double)(a.tv_sec - b.tv_sec) + + 0.000000001 * (double)(a.tv_nsec - b.tv_nsec); +} + static int timespec_cmp(struct timespec a, struct timespec b) { if (a.tv_sec > b.tv_sec) return 1; if (a.tv_sec < b.tv_sec) return -1; |