From 0cf52e2f5bc1e5e7f243e45eecfe3060ffeda6f2 Mon Sep 17 00:00:00 2001 From: Florian Fischer <florian.fischer@muhq.space> Date: Mon, 2 Aug 2021 14:19:33 +0200 Subject: [PATCH] make experiment size adjustable --- bench.c | 16 ++++++++++------ common.h | 2 ++ paio-thrd.c | 4 ++++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/bench.c b/bench.c index 4199b1e..2a2494d 100644 --- a/bench.c +++ b/bench.c @@ -12,8 +12,8 @@ void init(int fd); void do_write(int fd, const void *buf, size_t count); -const size_t warmup = 10000; -const size_t iterations = 1000000; +size_t warmup = 10000; +size_t iterations = 1000000; #define BUFSIZE 64 @@ -44,10 +44,14 @@ int main() { int fd = create_eventfd(); init(fd); + const size_t exp_warmup = warmup; + const size_t exp_iterations = iterations; - for (size_t i = 0; i < warmup; ++i) do_write(fd, &write_buf, sizeof(write_buf)); + if (exp_iterations == 0) errx(EXIT_FAILURE, "experiment must do at least one iteration"); - for (int64_t i = 1; i <= iterations; ++i) { + for (size_t i = 0; i < exp_warmup; ++i) do_write(fd, &write_buf, sizeof(write_buf)); + + for (int64_t i = 1; i <= exp_iterations; ++i) { do_write(fd, &write_buf, sizeof(write_buf)); if (__builtin_add_overflow(nanos_sum, clock_diff_nanos(), &nanos_sum)) errx(EXIT_FAILURE, "nanos overflowed at %ld", i); @@ -58,8 +62,8 @@ int main() { // Since uint64_t <-> double conversion are not well defined // and we use really small units (cycles and nanoseconds) I am willing // to accept that we throw away anything after the decimal point. - uint64_t avg_nanos = nanos_sum / iterations; - uint64_t avg_cycles = cycles_sum / iterations; + uint64_t avg_nanos = nanos_sum / exp_iterations; + uint64_t avg_cycles = cycles_sum / exp_iterations; printf("%lu ns, %lu cycles\n", avg_nanos, avg_cycles); return 0; diff --git a/common.h b/common.h index b8acbfd..80360f2 100644 --- a/common.h +++ b/common.h @@ -1,3 +1,5 @@ #pragma once #define unlikely(x) __builtin_expect(!!(x), 0) + +extern size_t warmup, iterations; diff --git a/paio-thrd.c b/paio-thrd.c index ef7c365..f2809af 100644 --- a/paio-thrd.c +++ b/paio-thrd.c @@ -5,6 +5,7 @@ #include <stdint.h> #include <stdlib.h> +#include "common.h" #include "stopwatch.h" atomic_int done; @@ -19,6 +20,9 @@ void callback(union sigval sigval) { } void init(int fd) { + // decrease the experiment size because this takes much longer than anything else + warmup = 10; + iterations = 100; aiocb.aio_fildes = fd; aiocb.aio_sigevent.sigev_notify = SIGEV_THREAD; aiocb.aio_sigevent.sigev_notify_function = callback; -- GitLab