From 4a30ed59b2e0fe870e10bd613ad40e58711cd16c Mon Sep 17 00:00:00 2001 From: jsing <> Date: Sun, 29 Jan 2023 15:51:26 +0000 Subject: Use utime in order to make benchmarks less noisy and more consistent. --- src/regress/lib/libcrypto/bn/bn_mul_div.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/regress/lib/libcrypto/bn/bn_mul_div.c b/src/regress/lib/libcrypto/bn/bn_mul_div.c index 77805b9a80..278f8d715b 100644 --- a/src/regress/lib/libcrypto/bn/bn_mul_div.c +++ b/src/regress/lib/libcrypto/bn/bn_mul_div.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bn_mul_div.c,v 1.4 2023/01/29 15:33:43 jsing Exp $ */ +/* $OpenBSD: bn_mul_div.c,v 1.5 2023/01/29 15:51:26 jsing Exp $ */ /* * Copyright (c) 2023 Joel Sing * @@ -15,6 +15,7 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include #include #include @@ -338,6 +339,7 @@ static void benchmark_run(const struct benchmark *bm, int seconds) { struct timespec start, end, duration; + struct rusage rusage; BIGNUM *a, *b, *r, *q; BN_CTX *bn_ctx; int i; @@ -368,17 +370,24 @@ benchmark_run(const struct benchmark *bm, int seconds) i = 0; alarm(seconds); - clock_gettime(CLOCK_MONOTONIC, &start); + if (getrusage(RUSAGE_SELF, &rusage) == -1) + err(1, "getrusage failed"); + TIMEVAL_TO_TIMESPEC(&rusage.ru_utime, &start); fprintf(stderr, "Benchmarking %s for %ds: ", bm->desc, seconds); while (!benchmark_stop) { bm->run_once(r, q, a, b, bn_ctx); i++; } - clock_gettime(CLOCK_MONOTONIC, &end); + if (getrusage(RUSAGE_SELF, &rusage) == -1) + err(1, "getrusage failed"); + TIMEVAL_TO_TIMESPEC(&rusage.ru_utime, &end); + timespecsub(&end, &start, &duration); - fprintf(stderr, "%d iterations in %f seconds\n", i, - duration.tv_sec + duration.tv_nsec / 1000000000.0); + fprintf(stderr, "%d iterations in %f seconds - %llu op/s\n", i, + duration.tv_sec + duration.tv_nsec / 1000000000.0, + (size_t)i * 1000000000 / + (duration.tv_sec * 1000000000 + duration.tv_nsec)); BN_CTX_end(bn_ctx); BN_CTX_free(bn_ctx); -- cgit v1.2.3-55-g6feb