]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-process-util: run fewer getpid() tests
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 2 Apr 2021 09:44:48 +0000 (11:44 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 5 May 2021 11:59:23 +0000 (13:59 +0200)
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

index 383e9ae3c5e48bdee359eda21ef085eea70f5b4b..957d23ffc54d317b30fbb6687156e9e7fe53bd91 100644 (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) {