[babl] tools/babl-benchmark: add unicode barchart to results



commit 64e2c0611937d60892a14875614071f322558cc5
Author: Øyvind Kolås <pippin gimp org>
Date:   Sun Aug 20 21:05:52 2017 +0200

    tools/babl-benchmark: add unicode barchart to results

 tools/babl-benchmark.c |   76 +++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 62 insertions(+), 14 deletions(-)
---
diff --git a/tools/babl-benchmark.c b/tools/babl-benchmark.c
index 7e51bc4..a887f5c 100644
--- a/tools/babl-benchmark.c
+++ b/tools/babl-benchmark.c
@@ -20,12 +20,39 @@
 #include <math.h>
 #include "babl-internal.h"
 
-int ITERATIONS = 1;
-#define  N_PIXELS (512*512)
+int ITERATIONS = 2;
+#define  N_PIXELS (512*1024)  // a too small batch makes the test set live
+                               // in l2 cache skewing results
+
+                               // we could also add a cache purger..
 
 
 #define  N_BYTES  N_PIXELS * (4 * 8)
 
+static const char *unicode_hbar (int width, double fraction)
+{
+  static char ret[200]="";
+  const char *block[9]= {" ", "▏", "▎", "▍", "▌", "▋", "▊", "▉","█"};
+  int i;
+  if (width > 100) width = 100;
+
+  ret[0]=0;
+  for (i = 0; i < width; i++)
+  {
+    double start = i * 1.0 / width;
+    if (start < fraction)
+      strcat (ret, block[8]);
+    else
+    {
+      double miss = (start - fraction) * width;
+      if (miss < 1.0)
+        strcat (ret, block[(int)((1.0-miss) * 8.999)]);
+      else
+        strcat (ret, block[0]);
+    }
+  }
+  return ret;
+}
 
 static int
 test (void)
@@ -37,42 +64,50 @@ test (void)
   char *dst_data = babl_malloc (N_BYTES);
   double sum = 0;
 
+
   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("R'G'B'A u8",     babl_space("ProPhoto")),
      babl_format_with_space("RGBA float",     babl_space("ProPhoto")),
      babl_format_with_space("R'G'B' u16",     babl_space("ProPhoto")),
-     babl_format("CIE Lab float"),
 #endif
      babl_format("RGBA float"),
      babl_format("R'G'B'A float"),
      babl_format("R'G'B' u8"),
+     babl_format("CIE Lab float"),
      babl_format_with_space("R'G'B' u8",     babl_space("Adobe")),
      babl_format_with_space("R'G'B' u8",     babl_space("ProPhoto")),
-     babl_format_with_space("RGBA float",     babl_space("ProPhoto")),
-     babl_format_with_space("R'G'B'A float",  babl_space("ProPhoto"))
+     babl_format_with_space("Y float",       babl_space("ProPhoto")),
+     babl_format_with_space("R'G'B'A float", babl_space("ProPhoto")),
+     babl_format_with_space("RGBA float",    babl_space("ProPhoto"))
      };
   int n_formats = sizeof (formats) / sizeof (formats[0]);
+  double mbps[50 * 50] = {0,};
+  int n;
+  double max = 0.0;
+
+  assert (n_formats < 50);
 
  for (i = 0; i < N_BYTES; i++)
    src_data[i] = random();
 
+
  fprintf (stdout,"%i iterations of %i pixels, mb/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++)
    {
       const Babl *fish = babl_fish (formats[i], formats[j]);
       long end, start;
-      double megabytes_per_sec;
       int iters = ITERATIONS;
 
-#if 1
       fprintf (stderr, "%s to %s\r", babl_get_name (formats[i]),
                                      babl_get_name (formats[j]));
-#endif
+      fflush (0);
 
       /* a quarter round of warmup */
       babl_process (fish, src_data, dst_data, N_PIXELS * 0.25);
@@ -82,19 +117,32 @@ test (void)
         babl_process (fish, src_data, dst_data, N_PIXELS);
       }
       end = babl_ticks ();
-      megabytes_per_sec = (babl_format_get_bytes_per_pixel (formats[i]) +
+      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));
 
-      sum += megabytes_per_sec;
-      fprintf (stdout, " %03.1f mb/s\t%s to %s\n",
-                       megabytes_per_sec,
+      sum += mbps[n];
+      if (mbps[n] > max)
+        max = mbps[n];
+      n++;
+   }
+
+ n = 0;
+ for (i = 0; i < n_formats; i++)
+   for (j = 0; j < n_formats; j++)
+   {
+      fprintf (stdout, "%s %03.1f mb/s\t%s to %s\n",
+                      unicode_hbar(16, mbps[n] / max),
+                      mbps[n],
                       babl_get_name (formats[i]),
                       babl_get_name (formats[j]));
-      fflush (0);
+      n++;
    }
+  fprintf (stdout, "\n%s %03.1f mb/s\taverage\n",
+                      unicode_hbar(16, sum / (n_formats * n_formats) / max),
+                      sum / (n_formats * n_formats));
 
- fprintf (stdout,"%3.1f mb/s\taverage\n", sum / (n_formats * n_formats));
+  fflush (0);
 
   if (!OK)
     return -1;


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