From 59994bdd2259a59ece2e4e0b1e5f47832b40997b Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 29 Jan 2020 11:05:24 +0100 Subject: [PATCH] performance test: Produce better numbers Try to isolate the test runs from each other in the eyes of the kernel scheduler, by sleeping a bit. And ignore the first run, to avoid cache effects. --- testsuite/performance/test-performance.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/testsuite/performance/test-performance.c b/testsuite/performance/test-performance.c index 2dfbe3da66..fc0a7cfc36 100644 --- a/testsuite/performance/test-performance.c +++ b/testsuite/performance/test-performance.c @@ -56,6 +56,7 @@ main (int argc, char *argv[]) char fd_str[20]; gint64 *values; gint64 min, max, total; + int count; char *output_dir = NULL; int i; @@ -89,6 +90,8 @@ main (int argc, char *argv[]) g_object_unref (file); } + opt_rep++; + values = g_new (gint64, opt_rep); for (i = 0; i < opt_rep; i++) @@ -101,9 +104,9 @@ main (int argc, char *argv[]) SysprofCaptureCursor *cursor; SysprofCaptureCondition *condition; - fd = g_file_open_tmp ("gtk.XXXXXX.syscap", &name, &error); - if (error) - g_error ("Create syscap file: %s", error->message); + fd = g_file_open_tmp ("gtk.XXXXXX.syscap", &name, &error); + if (error) + g_error ("Create syscap file: %s", error->message); launcher = g_subprocess_launcher_new (0); g_subprocess_launcher_take_fd (launcher, fd, fd); @@ -164,24 +167,30 @@ main (int argc, char *argv[]) remove (name); g_free (name); + + /* A poor mans way to try and isolate the runs from each other */ + g_usleep (300000); } min = G_MAXINT64; max = 0; + count = 0; total = 0; - for (i = 0; i < opt_rep; i++) + /* Ignore the first run, to avoid cache effects */ + for (i = 1; i < opt_rep; i++) { if (min > values[i]) min = values[i]; if (max < values[i]) max = values[i]; + count++; total += values[i]; } g_print ("%d runs, min %g, max %g, avg %g\n", - opt_rep, + count, MILLISECONDS (min), MILLISECONDS (max), - MILLISECONDS (total / opt_rep)); + MILLISECONDS (total / count)); }