chiark / gitweb /
test: determine number of transactions per second rather than time per transaction
authorLennart Poettering <lennart@poettering.net>
Mon, 3 Jun 2013 10:44:44 +0000 (19:44 +0900)
committerLennart Poettering <lennart@poettering.net>
Tue, 4 Jun 2013 09:53:11 +0000 (11:53 +0200)
This way the measurements are not skewed by twoo short total measurement
times, and results become stabler.

src/libsystemd-bus/test-bus-kernel-benchmark.c

index 0cf685e..01074dd 100644 (file)
@@ -24,6 +24,7 @@
 
 #include "util.h"
 #include "log.h"
+#include "time-util.h"
 
 #include "sd-bus.h"
 #include "bus-message.h"
 #include "bus-kernel.h"
 #include "bus-internal.h"
 
-#define N_TRIES 10000
 #define MAX_SIZE (1*1024*1024)
 
+static usec_t arg_loop_usec = 10 * USEC_PER_SEC;
+
 static void server(sd_bus *b, size_t *result) {
         int r;
 
@@ -107,8 +109,8 @@ static void client(const char *address) {
         rsize = MAX_SIZE;
 
         for (;;) {
-                usec_t copy, memfd, t;
-                unsigned i;
+                usec_t t;
+                unsigned n_copying, n_memfd;
 
                 csize = (lsize + rsize) / 2;
 
@@ -122,24 +124,32 @@ static void client(const char *address) {
 
                 log_info("copying...");
                 b->use_memfd = 0;
+
                 t = now(CLOCK_MONOTONIC);
-                for (i = 0; i <  N_TRIES; i++)
+                for (n_copying = 0;; n_copying++) {
                         transaction(b, csize);
-                copy = (now(CLOCK_MONOTONIC) - t);
-                log_info("%llu usec per copy transaction", (unsigned long long) (copy / N_TRIES));
+                        if (now(CLOCK_MONOTONIC) >= t + arg_loop_usec)
+                                break;
+                }
+
+                log_info("%u copy transactions per second", (unsigned) ((n_copying * USEC_PER_SEC) / arg_loop_usec));
 
                 log_info("sending memfd...");
                 b->use_memfd = -1;
+
                 t = now(CLOCK_MONOTONIC);
-                for (i = 0; i <  N_TRIES; i++)
+                for (n_memfd = 0;; n_memfd++) {
                         transaction(b, csize);
-                memfd = (now(CLOCK_MONOTONIC) - t);
-                log_info("%llu usec per memfd transaction", (unsigned long long) (memfd / N_TRIES));
+                        if (now(CLOCK_MONOTONIC) >= t + arg_loop_usec)
+                                break;
+                }
 
-                if (copy == memfd)
+                log_info("%u memfd transactions per second", (unsigned) ((n_memfd * USEC_PER_SEC) / arg_loop_usec));
+
+                if (n_copying == n_memfd)
                         break;
 
-                if (copy < memfd)
+                if (n_copying > n_memfd)
                         lsize = csize;
                 else
                         rsize = csize;
@@ -163,6 +173,11 @@ int main(int argc, char *argv[]) {
 
         log_set_max_level(LOG_DEBUG);
 
+        if (argc > 1)
+                assert_se(parse_sec(argv[1], &arg_loop_usec) >= 0);
+
+        assert_se(arg_loop_usec > 0);
+
         bus_ref = bus_kernel_create("deine-mutter", &bus_name);
         if (bus_ref == -ENOENT)
                 exit(EXIT_TEST_SKIP);