From bd82d030011cd8b9655e5ded6b6df9343b42a6bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Wed, 4 Feb 2015 14:09:54 +0100 Subject: Imported Upstream version 3.22 --- src/tc-rand.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/tc-rand.c (limited to 'src/tc-rand.c') diff --git a/src/tc-rand.c b/src/tc-rand.c new file mode 100644 index 0000000..3af45d0 --- /dev/null +++ b/src/tc-rand.c @@ -0,0 +1,49 @@ +/* + * Copyright Jan Engelhardt + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the WTF Public License version 2 or + * (at your option) any later version. + */ +#include +#include +#include +#include +#include +#include "internal.h" + +int main(void) +{ + struct timespec past, now, delta; + unsigned int i; + + if (HX_init() <= 0) + abort(); + for (i = 0; i < 15; ++i) { + printf("%d ", HX_irand(i, i)); + printf("%.1f ", HX_drand(i, i)); + printf("%08x, ", HX_irand(0, RAND_MAX)); + } + printf("\n"); + + clock_gettime(CLOCK_REALTIME, &past); + for (i = 0; i < (1 << 25); ++i) { + volatile unsigned int __attribute__((unused)) t = + HX_irand(0, RAND_MAX); + } + clock_gettime(CLOCK_REALTIME, &now); + HX_timespec_sub(&delta, &now, &past); + printf("%% method: " HX_TIMESPEC_FMT " s\n", HX_TIMESPEC_EXP(&delta)); + + clock_gettime(CLOCK_REALTIME, &past); + for (i = 0; i < (1 << 25); ++i) { + volatile unsigned int __attribute__((unused)) t = + HX_irand(0, ~0U); + } + clock_gettime(CLOCK_REALTIME, &now); + HX_timespec_sub(&delta, &now, &past); + printf("/ method: " HX_TIMESPEC_FMT " s\n", HX_TIMESPEC_EXP(&delta)); + + HX_exit(); + return EXIT_SUCCESS; +} -- cgit v1.2.3