13typedef struct timespec Instant;
16static inline Instant now() {
18 clock_gettime(CLOCK_MONOTONIC_RAW, &clock);
22static inline double interval_usec(Instant
const *end, Instant
const *start) {
23 return (end->tv_sec - start->tv_sec) * 1.e6 + (end->tv_nsec - start->tv_nsec) * 1.e-3;
27static inline uint_fast64_t interval_nsec(Instant
const *end, Instant
const *start) {
28 return (end->tv_sec - start->tv_sec) * (uint_fast64_t)(1000000000U) + (end->tv_nsec - start->tv_nsec);
37static inline void timer_set(
Timer *t) {
38 Instant
const n = now();
44static inline double timer_read(
Timer const *t) {
45 Instant
const n = now();
46 return interval_usec(&n, &(t->start));
50static inline double timer_lap(
Timer *t) {
51 Instant
const l = now();
52 double laptime = interval_usec(&l, &(t->lap));
58static inline double timer_res() {
60 clock_getres(CLOCK_MONOTONIC_RAW, &res);
61 return res.tv_sec * 1.e6 + res.tv_nsec * 1.e-3;
65int timeval_subtract(
struct timeval *result,
struct timeval *x,
struct timeval *y);