diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2021-04-02 11:44:48 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2021-05-05 13:59:23 +0200 |
commit | 07468a16e46dba9da8b9c8593e0c2ee5bfec3c69 (patch) | |
tree | f71b2d551f8312b6a6003ad3a5bd9e556457e94e /src/test/test-process-util.c | |
parent | daceaabe1f87de85a404499d95c6f351b83fb3d9 (diff) | |
download | systemd-07468a16e46dba9da8b9c8593e0c2ee5bfec3c69.tar.gz |
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.
Diffstat (limited to 'src/test/test-process-util.c')
-rw-r--r-- | src/test/test-process-util.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/test/test-process-util.c b/src/test/test-process-util.c index 383e9ae3c5..957d23ffc5 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) { |