diff options
author | jsing <> | 2023-01-29 15:51:26 +0000 |
---|---|---|
committer | jsing <> | 2023-01-29 15:51:26 +0000 |
commit | 4a30ed59b2e0fe870e10bd613ad40e58711cd16c (patch) | |
tree | 5298e1f0a224d20b93b72abb5e8e0e47d6cc6d55 /src | |
parent | c66da55bf83b33c7f819d7ad8cef1c38dfef07e0 (diff) | |
download | openbsd-4a30ed59b2e0fe870e10bd613ad40e58711cd16c.tar.gz openbsd-4a30ed59b2e0fe870e10bd613ad40e58711cd16c.tar.bz2 openbsd-4a30ed59b2e0fe870e10bd613ad40e58711cd16c.zip |
Use utime in order to make benchmarks less noisy and more consistent.
Diffstat (limited to 'src')
-rw-r--r-- | src/regress/lib/libcrypto/bn/bn_mul_div.c | 19 |
1 files changed, 14 insertions, 5 deletions
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 @@ | |||
1 | /* $OpenBSD: bn_mul_div.c,v 1.4 2023/01/29 15:33:43 jsing Exp $ */ | 1 | /* $OpenBSD: bn_mul_div.c,v 1.5 2023/01/29 15:51:26 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2023 Joel Sing <jsing@openbsd.org> |
4 | * | 4 | * |
@@ -15,6 +15,7 @@ | |||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
16 | */ | 16 | */ |
17 | 17 | ||
18 | #include <sys/resource.h> | ||
18 | #include <sys/time.h> | 19 | #include <sys/time.h> |
19 | 20 | ||
20 | #include <err.h> | 21 | #include <err.h> |
@@ -338,6 +339,7 @@ static void | |||
338 | benchmark_run(const struct benchmark *bm, int seconds) | 339 | benchmark_run(const struct benchmark *bm, int seconds) |
339 | { | 340 | { |
340 | struct timespec start, end, duration; | 341 | struct timespec start, end, duration; |
342 | struct rusage rusage; | ||
341 | BIGNUM *a, *b, *r, *q; | 343 | BIGNUM *a, *b, *r, *q; |
342 | BN_CTX *bn_ctx; | 344 | BN_CTX *bn_ctx; |
343 | int i; | 345 | int i; |
@@ -368,17 +370,24 @@ benchmark_run(const struct benchmark *bm, int seconds) | |||
368 | i = 0; | 370 | i = 0; |
369 | alarm(seconds); | 371 | alarm(seconds); |
370 | 372 | ||
371 | clock_gettime(CLOCK_MONOTONIC, &start); | 373 | if (getrusage(RUSAGE_SELF, &rusage) == -1) |
374 | err(1, "getrusage failed"); | ||
375 | TIMEVAL_TO_TIMESPEC(&rusage.ru_utime, &start); | ||
372 | 376 | ||
373 | fprintf(stderr, "Benchmarking %s for %ds: ", bm->desc, seconds); | 377 | fprintf(stderr, "Benchmarking %s for %ds: ", bm->desc, seconds); |
374 | while (!benchmark_stop) { | 378 | while (!benchmark_stop) { |
375 | bm->run_once(r, q, a, b, bn_ctx); | 379 | bm->run_once(r, q, a, b, bn_ctx); |
376 | i++; | 380 | i++; |
377 | } | 381 | } |
378 | clock_gettime(CLOCK_MONOTONIC, &end); | 382 | if (getrusage(RUSAGE_SELF, &rusage) == -1) |
383 | err(1, "getrusage failed"); | ||
384 | TIMEVAL_TO_TIMESPEC(&rusage.ru_utime, &end); | ||
385 | |||
379 | timespecsub(&end, &start, &duration); | 386 | timespecsub(&end, &start, &duration); |
380 | fprintf(stderr, "%d iterations in %f seconds\n", i, | 387 | fprintf(stderr, "%d iterations in %f seconds - %llu op/s\n", i, |
381 | duration.tv_sec + duration.tv_nsec / 1000000000.0); | 388 | duration.tv_sec + duration.tv_nsec / 1000000000.0, |
389 | (size_t)i * 1000000000 / | ||
390 | (duration.tv_sec * 1000000000 + duration.tv_nsec)); | ||
382 | 391 | ||
383 | BN_CTX_end(bn_ctx); | 392 | BN_CTX_end(bn_ctx); |
384 | BN_CTX_free(bn_ctx); | 393 | BN_CTX_free(bn_ctx); |