Add nstime_ns_since which obtains the duration since the input time.

This commit is contained in:
Qi Wang
2021-12-20 14:39:24 -08:00
committed by Qi Wang
parent cafe9a3158
commit 310af725b0
3 changed files with 42 additions and 0 deletions

View File

@@ -158,6 +158,19 @@ nstime_divide(const nstime_t *time, const nstime_t *divisor) {
return time->ns / divisor->ns;
}
/* Returns time since *past, w/o updating *past. */
uint64_t
nstime_ns_since(const nstime_t *past) {
nstime_assert_initialized(past);
nstime_t now;
nstime_copy(&now, past);
nstime_update(&now);
assert(nstime_compare(&now, past) >= 0);
return now.ns - past->ns;
}
#ifdef _WIN32
# define NSTIME_MONOTONIC true
static void