]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Add benchmark for sha256 calculations 20915/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 8 Oct 2021 07:35:50 +0000 (09:35 +0200)
committerLuca Boccassi <luca.boccassi@microsoft.com>
Fri, 8 Oct 2021 12:11:00 +0000 (13:11 +0100)
src/test/test-id128.c

index f6755f20cce3dde4e3aff070274e30a00174236a..79dc7de159fce85006c1f7da07938af80e21bb86 100644 (file)
@@ -168,11 +168,33 @@ static void test_sd_id128_get_invocation(void) {
                 log_info("Invocation ID: " SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(id));
 }
 
+static void benchmark_sd_id128_get_machine_app_specific(void) {
+        unsigned iterations = slow_tests_enabled() ? 1000000 : 1000;
+        usec_t t, q;
+
+        log_info("/* %s (%u iterations) */", __func__, iterations);
+
+        sd_id128_t id = ID128_WALDI, id2;
+
+        t = now(CLOCK_MONOTONIC);
+
+        for (unsigned i = 0; i < iterations; i++) {
+                id.qwords[1] = i;
+
+                assert_se(sd_id128_get_machine_app_specific(id, &id2) >= 0);
+        }
+
+        q = now(CLOCK_MONOTONIC) - t;
+
+        log_info("%lf µs each\n", (double) q / iterations);
+}
+
 int main(int argc, char *argv[]) {
         test_setup_logging(LOG_INFO);
 
         test_id128();
         test_sd_id128_get_invocation();
+        benchmark_sd_id128_get_machine_app_specific();
 
         return 0;
 }