[babl] tools: rework babl-benchmark to operate on sets resembling workingspace + GEGL + display



commit b8e1066cebc175c3d8503763de3ca3fd71046546
Author: Øyvind Kolås <pippin gimp org>
Date:   Sun Jan 23 07:30:28 2022 +0100

    tools: rework babl-benchmark to operate on sets resembling workingspace + GEGL + display

 tools/babl-benchmark.c | 168 +++++++++++++++++++++++++++++++++++--------------
 1 file changed, 121 insertions(+), 47 deletions(-)
---
diff --git a/tools/babl-benchmark.c b/tools/babl-benchmark.c
index 1fd9e78..445974c 100644
--- a/tools/babl-benchmark.c
+++ b/tools/babl-benchmark.c
@@ -25,12 +25,13 @@
 #define random  rand
 #endif
 
-int ITERATIONS = 1;
-#define  N_PIXELS (512*1024)  // a too small batch makes the test set live
+int ITERATIONS = 100;
+#define  N_PIXELS (512*256)  // a too small batch makes the test set live
                                // in l2 cache skewing results
 
                                // we could also add a cache purger..
 
+int unit_pixels = 1; // use megapixels per second instead of bytes
 
 #define  N_BYTES  N_PIXELS * (4 * 8)
 
@@ -62,7 +63,7 @@ unicode_hbar (int    width,
 }
 
 static int
-test (void)
+test (int set_no)
 {
   int i, j;
   int OK = 1;
@@ -71,57 +72,111 @@ test (void)
   char *dst_data = babl_malloc (N_BYTES);
   double sum = 0;
 
+#define default_set(space, out_space) \
+       babl_format_with_space("RGBA float", babl_space(space)), \
+       babl_format_with_space("RaGaBaA float", babl_space(space)), \
+       babl_format_with_space("R'G'B'A float", babl_space(space)), \
+       babl_format_with_space("cairo-ARGB32", babl_space(out_space)) 
+
+  const Babl **formats=NULL;
+  const Babl *format_sets[][20]={
+        { babl_format_with_space("R'G'B'A u8", babl_space("sRGB")), default_set("sRGB", "sRGB"), NULL },
+        { babl_format_with_space("R'G'B'A u16", babl_space("sRGB")), default_set("sRGB", "sRGB"), NULL },
+        { babl_format_with_space("R'G'B'A half", babl_space("sRGB")), default_set("sRGB", "sRGB"), NULL },
+        { babl_format_with_space("R'G'B'A float", babl_space("sRGB")), default_set("sRGB", "sRGB"), NULL },
+        { babl_format_with_space("RGBA u16", babl_space("sRGB")), default_set("sRGB", "sRGB"), NULL },
+        { babl_format_with_space("RGBA half", babl_space("sRGB")), default_set("sRGB", "sRGB"), NULL },
+        { babl_format_with_space("RGBA float", babl_space("sRGB")), default_set("sRGB", "sRGB"), NULL },
+        { babl_format_with_space("Y' u8", babl_space("sRGB")), default_set("sRGB", "sRGB"), NULL },
+        { babl_format_with_space("Y' u16", babl_space("sRGB")), default_set("sRGB", "sRGB"), NULL },
+        { babl_format_with_space("Y' half", babl_space("sRGB")), default_set("sRGB", "sRGB"), NULL },
+        { babl_format_with_space("Y' float", babl_space("sRGB")), default_set("sRGB", "sRGB"), NULL },
+        { babl_format_with_space("Y u8", babl_space("sRGB")), default_set("sRGB", "sRGB"), NULL },
+        { babl_format_with_space("Y u16", babl_space("sRGB")), default_set("sRGB", "sRGB"), NULL },
+        { babl_format_with_space("Y half", babl_space("sRGB")), default_set("sRGB", "sRGB"), NULL },
+        { babl_format_with_space("Y float", babl_space("sRGB")), default_set("sRGB", "sRGB"), NULL },
 
-  const Babl *formats[]={
-#if 0
-     babl_format("R'G'B'A u8"),
-     babl_format("Y float"),
-     babl_format("R'G'B'A u16"),
-     babl_format_with_space("RGBA float",     babl_space("ProPhoto")),
-     babl_format_with_space("R'G'B' u16",     babl_space("ProPhoto")),
-#endif
-       //babl_format("R'G'B'A u8"),
-       babl_format("R'G'B'A u16"),
-       //babl_format_with_space("R'G'B'A u8", babl_space("ProPhoto")),
-       //babl_format_with_space("Y'A u8", babl_space("ProPhoto")),
-       babl_format_with_space("Y'A u16", babl_space("ProPhoto")),
-       babl_format_with_space("Y' u16", babl_space("ProPhoto")),
-       //babl_format_with_space("Y' u8", babl_space("ProPhoto")),
-       babl_format_with_space("Y float", babl_space("ProPhoto")),
-       babl_format_with_space("YaA float", babl_space("ProPhoto")),
-       babl_format_with_space("YA float", babl_space("ProPhoto")),
-       //babl_format_with_space("YA u16", babl_space("ProPhoto")),
-       //babl_format_with_space("R'G'B'A half", babl_space("ProPhoto")),
-       babl_format_with_space("R'G'B'A float", babl_space("ProPhoto")),
-       babl_format_with_space("RaGaBaA float", babl_space("ProPhoto")),
-       babl_format_with_space("cairo-RGB24", babl_space("Adobe")),
-       babl_format_with_space("cairo-ARGB32", babl_space("Adobe")),
 
+        { babl_format_with_space("R'G'B'A u8", babl_space("sRGB")), default_set("sRGB", "ProPhoto"), NULL },
+        { babl_format_with_space("R'G'B'A u16", babl_space("sRGB")), default_set("sRGB", "ProPhoto"), NULL },
+        { babl_format_with_space("R'G'B'A half", babl_space("sRGB")), default_set("sRGB", "ProPhoto"), NULL 
},
+        { babl_format_with_space("R'G'B'A float", babl_space("sRGB")), default_set("sRGB", "ProPhoto"), NULL 
},
+        { babl_format_with_space("RGBA u16", babl_space("sRGB")), default_set("sRGB", "ProPhoto"), NULL },
+        { babl_format_with_space("RGBA half", babl_space("sRGB")), default_set("sRGB", "ProPhoto"), NULL },
+        { babl_format_with_space("RGBA float", babl_space("sRGB")), default_set("sRGB", "ProPhoto"), NULL },
+        { babl_format_with_space("Y' u8", babl_space("sRGB")), default_set("sRGB", "ProPhoto"), NULL },
+        { babl_format_with_space("Y' u16", babl_space("sRGB")), default_set("sRGB", "ProPhoto"), NULL },
+        { babl_format_with_space("Y' half", babl_space("sRGB")), default_set("sRGB", "ProPhoto"), NULL },
+        { babl_format_with_space("Y' float", babl_space("sRGB")), default_set("sRGB", "ProPhoto"), NULL },
+        { babl_format_with_space("Y u8", babl_space("sRGB")), default_set("sRGB", "ProPhoto"), NULL },
+        { babl_format_with_space("Y u16", babl_space("sRGB")), default_set("sRGB", "ProPhoto"), NULL },
+        { babl_format_with_space("Y half", babl_space("sRGB")), default_set("sRGB", "ProPhoto"), NULL },
+        { babl_format_with_space("Y float", babl_space("sRGB")), default_set("sRGB", "ProPhoto"), NULL },
+
+        { babl_format_with_space("R'G'B'A u8", babl_space("Apple")), default_set("Apple", "ProPhoto"), NULL 
},
+        { babl_format_with_space("R'G'B'A u16", babl_space("Apple")), default_set("Apple", "ProPhoto"), NULL 
},
+        { babl_format_with_space("R'G'B'A half", babl_space("Apple")), default_set("Apple", "ProPhoto"), 
NULL },
+        { babl_format_with_space("R'G'B'A float", babl_space("Apple")), default_set("Apple", "ProPhoto"), 
NULL },
+        { babl_format_with_space("RGBA u16", babl_space("Apple")), default_set("Apple", "ProPhoto"), NULL },
+        { babl_format_with_space("RGBA half", babl_space("Apple")), default_set("Apple", "ProPhoto"), NULL },
+        { babl_format_with_space("RGBA float", babl_space("Apple")), default_set("Apple", "ProPhoto"), NULL 
},
+        { babl_format_with_space("Y' u8", babl_space("Apple")), default_set("Apple", "ProPhoto"), NULL },
+        { babl_format_with_space("Y' u16", babl_space("Apple")), default_set("Apple", "ProPhoto"), NULL },
+        { babl_format_with_space("Y' half", babl_space("Apple")), default_set("Apple", "ProPhoto"), NULL },
+        { babl_format_with_space("Y' float", babl_space("Apple")), default_set("Apple", "ProPhoto"), NULL },
+        { babl_format_with_space("Y u8", babl_space("Apple")), default_set("Apple", "ProPhoto"), NULL },
+        { babl_format_with_space("Y u16", babl_space("Apple")), default_set("Apple", "ProPhoto"), NULL },
+        { babl_format_with_space("Y half", babl_space("Apple")), default_set("Apple", "ProPhoto"), NULL },
+        { babl_format_with_space("Y float", babl_space("Apple")), default_set("Apple", "ProPhoto"), NULL },
      };
-  int n_formats = sizeof (formats) / sizeof (formats[0]);
+
+  int n_formats = 0;
+  int n_sets = sizeof(format_sets)/sizeof(format_sets[0]);
+
   const Babl *fishes[50 * 50];
   double mbps[50 * 50] = {0,};
   long n;
   double max = 0.0;
 
-  assert (n_formats < 50);
+  int show_details = 0;
+  int set_iter = 0;
+  int first_run = 1;
+
+  if (set_no > n_sets-1) set_no = n_sets-1;
+
+  while (set_iter < n_sets)
+  {
+  if (set_no >= 0)
+    formats=&format_sets[set_no][0];
+  else
+    formats=&format_sets[set_iter][0];
+
 
  for (i = 0; i < N_BYTES; i++)
    src_data[i] = random();
 
+ fprintf (stdout, "\n\n");
+ fprintf (stdout, "set %i formats:\n", set_iter);
+ for (i = 0; formats[i]; i++)
+ {
+   fprintf (stdout, "  %s\n", babl_get_name (formats[i]));
+   n_formats++;
+ }
+ fprintf (stdout, "\n");
 
- fprintf (stdout,"%i iterations of %i pixels, mb/s is for sum of source and destinations bytes\n", 
ITERATIONS, N_PIXELS);
+ //fprintf (stdout,"%i iterations of %i pixels, mp/s is for sum of source and destinations bytes\n", 
ITERATIONS, N_PIXELS);
+ 
 
  n = 0;
- for (i = 0; i < n_formats; i++)
-   for (j = 0; j < n_formats; j++)
+ for (i = 0; formats[i]; i++)
+   for (j = 0; formats[j]; j++)
    if (i != j)
    {
       const Babl *fish = babl_fish (formats[i], formats[j]);
       long end, start;
       int iters = ITERATIONS;
 
-      fprintf (stderr, "%s to %s          \r", babl_get_name (formats[i]),
+      fprintf (stdout, "%s to %s          \r", babl_get_name (formats[i]),
                                                babl_get_name (formats[j]));
       fflush (0);
 
@@ -134,27 +189,37 @@ test (void)
       }
       end = babl_ticks ();
       fishes[n] = fish;
-      mbps [n] = (babl_format_get_bytes_per_pixel (formats[i]) +
-                           babl_format_get_bytes_per_pixel (formats[j])) *
-              (N_PIXELS * ITERATIONS / 1024.0 / 1024.0) / ((end-start)/(1000.0*1000.0));
+      mbps [n] = (N_PIXELS * ITERATIONS / 1000.0 / 1000.0) / ((end-start)/(1000.0*1000.0));
+      if (!unit_pixels)
+        mbps [n] *= (babl_format_get_bytes_per_pixel (formats[i]) +
+                     babl_format_get_bytes_per_pixel (formats[j]));
 
       sum += mbps[n];
-      if (mbps[n] > max)
+      if (mbps[n] > max && first_run)
         max = mbps[n];
       n++;
    }
 
+
+  fprintf (stdout, "\n%s %03.1f mb/s\taverage\n",
+                      unicode_hbar(16, sum / (n_formats * n_formats - n_formats) / max),
+                      sum / (n_formats * n_formats - n_formats));
+
+
  n = 0;
- for (i = 0; i < n_formats; i++)
-   for (j = 0; j < n_formats; j++)
+ for (i = 0; formats[i]; i++)
+   for (j = 0; formats[j]; j++)
    if (i != j)
    {
-      fprintf (stdout, "%s %03.1f mb/s\t%s to %s %.9f",
+      fprintf (stdout, "%s %03.1f m%s/s\t%s to %s %.9f",
                       unicode_hbar(16, mbps[n] / max),
                       mbps[n],
+                     unit_pixels?"p":"b",
                       babl_get_name (formats[i]),
                       babl_get_name (formats[j]),
                       fishes[n]->fish.error);
+
+
       if (fishes[n]->class_type == BABL_FISH_REFERENCE)
       {
         fprintf (stdout, "[R]");
@@ -162,21 +227,24 @@ test (void)
       else if (fishes[n]->class_type == BABL_FISH_PATH)
       {
         int k;
-        //fprintf (stdout, "[%d]", fishes[n]->fish_path.conversion_list->count);
+        fprintf (stdout, "[%d]", fishes[n]->fish_path.conversion_list->count);
+        if (show_details)
+        {
         for (k = 0; k < fishes[n]->fish_path.conversion_list->count; k++)
         {
           fprintf (stdout, "\n\t\t\t\t%s", babl_get_name (
                    fishes[n]->fish_path.conversion_list->items[k]));
         }
+        }
       }
       fprintf (stdout, "\n");
       n++;
    }
-  fprintf (stdout, "\n%s %03.1f mb/s\taverage\n",
-                      unicode_hbar(16, sum / (n_formats * n_formats - n_formats) / max),
-                      sum / (n_formats * n_formats - n_formats));
 
   fflush (0);
+  set_iter++;
+  first_run = 0;
+  }
 
   if (!OK)
     return -1;
@@ -187,10 +255,16 @@ int
 main (int    argc,
       char **argv)
 {
-  if (argv[1]) ITERATIONS = atoi (argv[1]);
+  //if (argv[1]) ITERATIONS = atoi (argv[1]);
   babl_init ();
-  if (test ())
-    return -1;
+  if (argv[1])
+  {
+    if (test (atoi(argv[1])))
+      return -1;
+  }
+  else
+    if (test (-1))
+      return -1;
   babl_exit ();
   return 0;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]