From b26845a20355b55a2eefa6043c2ded73f8a5f235 Mon Sep 17 00:00:00 2001 From: Laurent Mazet Date: Sat, 4 Oct 2025 23:17:17 +0200 Subject: [PATCH] add a cycle test --- cycle.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 cycle.c diff --git a/cycle.c b/cycle.c new file mode 100644 index 0000000..5ebc8e7 --- /dev/null +++ b/cycle.c @@ -0,0 +1,48 @@ +/* depend: */ +/* cflags: */ +/* linker: mtime.o test.o stat.o -lm -lrt */ + +#include +#include +#include + +#include "mtime.h" +#include "test.h" + +/* global variables */ + +dts_t *deltas = NULL; +int nb_measurements = 0; + +char *message = "Cycle latency"; +void (*usage_ext) (FILE *) = NULL; +int (*parse_arg_ext) (char *) = NULL; + +int try = 0; + +#define MAXDUR 1000 +#define MINDUR 100 + +int test (dts_t *buffer, int nb) +{ + + /* set global variables */ + + deltas = buffer; + nb_measurements = nb; + + /* thread test */ + + for (int i = 0; i < nb_measurements; i++) { + + int duration = MINDUR * ((MAXDUR / MINDUR) * rand () / RAND_MAX); + + ts_t ts1, ts2; + sys_timestamp (&ts1); + usleep (duration); + sys_timestamp (&ts2); + deltas[i] = diff_timestamp (&ts2, &ts1) - duration; + } + + return 0; +} -- 2.30.2