From 053868677195e472ddbc5129c6248419911b4546 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Wed, 21 Jan 2009 00:01:56 +0100 Subject: [PATCH] Add the missing benchmarking files. --- benchmark.c | 30 ++++++++++++++++++++++++++++++ benchmark.h | 11 +++++++++++ 2 files changed, 41 insertions(+) create mode 100644 benchmark.c create mode 100644 benchmark.h diff --git a/benchmark.c b/benchmark.c new file mode 100644 index 0000000..8e773e5 --- /dev/null +++ b/benchmark.c @@ -0,0 +1,30 @@ +#include +#include +#include + +static struct timespec start_time; + +void start_benchmark_timer() +{ + if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start_time) == -1) { + perror("clock_gettime()"); + exit(1); + } +} + +static double timediff(const struct timespec* a, const struct timespec* b) +{ + return (double)(b->tv_sec - a->tv_sec) + + (double)(b->tv_nsec - a->tv_nsec) * 1e-9; +} + +double stop_benchmark_timer() +{ + struct timespec now; + if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &now) == -1) { + perror("clock_gettime()"); + exit(1); + } + + return timediff(&start_time, &now); +} diff --git a/benchmark.h b/benchmark.h new file mode 100644 index 0000000..2b9ee58 --- /dev/null +++ b/benchmark.h @@ -0,0 +1,11 @@ +#ifndef _BENCHMARK_H +#define _BENChMARK_H 1 + +// Benchmark timing functions for reading out used CPU time. Not thread-safe +// as they store the information in a global variable. +void start_benchmark_timer(); +double stop_benchmark_timer(); + +#endif /* !defined(_BENCHMARK_H) */ + + -- 2.39.2