From: Zbigniew Jędrzejewski-Szmek Date: Fri, 2 Apr 2021 09:44:48 +0000 (+0200) Subject: test-process-util: run fewer getpid() tests X-Git-Tag: v249-rc1~274^2~5 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=07468a16e46dba9da8b9c8593e0c2ee5bfec3c69;p=thirdparty%2Fsystemd.git 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. --- 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) {