From: Laurent MAZET Date: Mon, 3 Nov 2025 18:19:33 +0000 (+0100) Subject: check clock resolution X-Git-Tag: v1.1~10 X-Git-Url: https://secure.softndesign.org/git/?a=commitdiff_plain;h=7cc1836857f2ecbd09fa7a28b21cd25c4df897c7;p=benchmarks.git check clock resolution --- 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);