Skip to content
Snippets Groups Projects
Commit d50bb01a authored by Niels Möller's avatar Niels Möller
Browse files

(die): New function.

(TIME_END, TIME_START): Check return value from clock_gettime.

Rev: nettle/examples/nettle-benchmark.c:1.18
parent 17f90be1
No related branches found
No related tags found
No related merge requests found
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include <assert.h> #include <assert.h>
#include <errno.h> #include <errno.h>
#include <math.h> #include <math.h>
#include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
...@@ -94,14 +95,29 @@ static double frequency = 0.0; ...@@ -94,14 +95,29 @@ static double frequency = 0.0;
#define BENCH_ITERATIONS 10 #define BENCH_ITERATIONS 10
#endif #endif
static void
die(const char *format, ...)
{
va_list args;
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
exit(EXIT_FAILURE);
}
static double overhead = 0.0; static double overhead = 0.0;
#if HAVE_CLOCK_GETTIME && defined CLOCK_PROCESS_CPUTIME_ID #if HAVE_CLOCK_GETTIME && defined CLOCK_PROCESS_CPUTIME_ID
#define TIME_TYPE struct timespec #define TIME_TYPE struct timespec
#define TIME_START(start) clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &(start)) #define TIME_START(start) do { \
if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &(start)) < 0) \
die("clock_gettime failed: %s\n", strerror(errno)); \
} while (0)
#define TIME_END(elapsed, start) do { \ #define TIME_END(elapsed, start) do { \
struct timespec _time_end_after; \ struct timespec _time_end_after; \
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &_time_end_after); \ if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &_time_end_after) < 0) \
die("clock_gettime failed: %s\n", strerror(errno)); \
(elapsed) = _time_end_after.tv_sec - (start).tv_sec \ (elapsed) = _time_end_after.tv_sec - (start).tv_sec \
+ 1e-9 * (_time_end_after.tv_nsec - (start).tv_nsec); \ + 1e-9 * (_time_end_after.tv_nsec - (start).tv_nsec); \
} while (0) } while (0)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment