From 07468a16e46dba9da8b9c8593e0c2ee5bfec3c69 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Fri, 2 Apr 2021 11:44:48 +0200 Subject: [PATCH] test-process-util: run fewer getpid() tests Significant time was spent in the getpid() measurement code, which is not very important. So let's optimize this a bit by running the slower version less times, and only running both tests a lesser amount of times unless slow tests are enabled. This gives the better accuracy then before in slow mode, and still reasonable accuracy in fast mode without a noticable slowdown. --- src/test/test-process-util.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/test/test-process-util.c b/src/test/test-process-util.c index 383e9ae3c5e..957d23ffc54 100644 --- a/src/test/test-process-util.c +++ b/src/test/test-process-util.c @@ -595,27 +595,28 @@ static void test_getpid_cached(void) { assert_se(si.si_code == CLD_EXITED); } -#define MEASURE_ITERATIONS (10000000LLU) - static void test_getpid_measure(void) { - unsigned long long i; usec_t t, q; - log_info("/* %s */", __func__); + unsigned long long iterations = slow_tests_enabled() ? 1000000 : 1000; + + log_info("/* %s (%llu iterations) */", __func__, iterations); t = now(CLOCK_MONOTONIC); - for (i = 0; i < MEASURE_ITERATIONS; i++) + for (unsigned long long i = 0; i < iterations; i++) (void) getpid(); q = now(CLOCK_MONOTONIC) - t; - log_info(" glibc getpid(): %lf µs each\n", (double) q / MEASURE_ITERATIONS); + log_info(" glibc getpid(): %lf µs each\n", (double) q / iterations); + + iterations *= 50; /* _cached() is about 50 times faster, so we need more iterations */ t = now(CLOCK_MONOTONIC); - for (i = 0; i < MEASURE_ITERATIONS; i++) + for (unsigned long long i = 0; i < iterations; i++) (void) getpid_cached(); q = now(CLOCK_MONOTONIC) - t; - log_info("getpid_cached(): %lf µs each\n", (double) q / MEASURE_ITERATIONS); + log_info("getpid_cached(): %lf µs each\n", (double) q / iterations); } static void test_safe_fork(void) { -- 2.47.3