performance test: Produce better numbers
authorMatthias Clasen <mclasen@redhat.com>
Wed, 29 Jan 2020 10:05:24 +0000 (11:05 +0100)
committerMatthias Clasen <mclasen@redhat.com>
Wed, 29 Jan 2020 10:06:32 +0000 (11:06 +0100)
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

index 2dfbe3da667dd7b0f946f2dbe8c6a6f4f6d0bce8..fc0a7cfc36202727c1c5bf16d498f5528b798875 100644 (file)
@@ -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));
 }