From 7cc1836857f2ecbd09fa7a28b21cd25c4df897c7 Mon Sep 17 00:00:00 2001 From: Laurent MAZET Date: Mon, 3 Nov 2025 19:19:33 +0100 Subject: [PATCH] check clock resolution --- mtime.c | 13 +++++++++++++ mtime.h | 2 ++ 2 files changed, 15 insertions(+) diff --git a/mtime.c b/mtime.c index 67c6ee7..f1ca364 100644 --- a/mtime.c +++ b/mtime.c @@ -1,7 +1,20 @@ +#include #include #include "mtime.h" +int res_timestamp (void) +{ + struct timespec ts; + int res = 0; + if (clock_getres (CLOCK_REALTIME, &ts) == -1) { + fprintf (stderr, "error: clock_getres\n"); + } else { + res = ts.tv_nsec; + } + return res; +} + dts_t diff_timestamp (ts_t *ts1, ts_t *ts2) { return (dts_t)(ts1->tv_sec - ts2->tv_sec) * 1000000000 + diff --git a/mtime.h b/mtime.h index 369d046..69343b0 100644 --- a/mtime.h +++ b/mtime.h @@ -9,6 +9,8 @@ typedef struct timespec ts_t; typedef long int dts_t; +int res_timestamp (void); + #define sys_timestamp(ts) clock_gettime (CLOCK_REALTIME, (ts)) dts_t diff_timestamp (ts_t *ts1, ts_t *ts2); -- 2.30.2