1
0
mirror of https://github.com/systemd/systemd.git synced 2024-10-30 23:21:22 +03:00

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.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2021-04-02 11:44:48 +02:00
parent daceaabe1f
commit 07468a16e4

View File

@ -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) {