r3993 - in trunk/birnet: . tests



Author: timj
Date: 2006-10-20 21:51:14 -0400 (Fri, 20 Oct 2006)
New Revision: 3993

Modified:
   trunk/birnet/ChangeLog
   trunk/birnet/birnetcdefs.h
   trunk/birnet/birnettests.h
   trunk/birnet/birnetutils.cc
   trunk/birnet/tests/Makefile.am
   trunk/birnet/tests/sorting.cc
   trunk/birnet/tests/strings.cc
   trunk/birnet/tests/threads.cc
Log:
Sat Oct 21 03:46:05 2006  Tim Janik  <timj gtk org>

        * birnettests.h: added treport_maximized() and treport_minimized()
        benchmark reporting funcitons. added TUnitType to allow specification
        of units for benchmark results.

        * birnetcdefs.h:
        * birnetutils.cc: parse --g-fatal-warnings, --test-quick, --test-slow
        and --test-perf. allow special casing of tests via 
        birnet_init_settings->test_quick, birnet_init_settings->test_slow and
        birnet_init_settings->test_perf.

        * tests/sorting.cc:
        * tests/strings.cc:
        * tests/threads.cc:
        * tests/Makefile.am: split up TESTS into SLOWTESTS and PERFTESTS and
        report performance results properly.




Modified: trunk/birnet/ChangeLog
===================================================================
--- trunk/birnet/ChangeLog	2006-10-20 21:09:48 UTC (rev 3992)
+++ trunk/birnet/ChangeLog	2006-10-21 01:51:14 UTC (rev 3993)
@@ -1,3 +1,21 @@
+Sat Oct 21 03:46:05 2006  Tim Janik  <timj gtk org>
+
+	* birnettests.h: added treport_maximized() and treport_minimized()
+	benchmark reporting funcitons. added TUnitType to allow specification
+	of units for benchmark results.
+
+	* birnetcdefs.h:
+	* birnetutils.cc: parse --g-fatal-warnings, --test-quick, --test-slow
+	and --test-perf. allow special casing of tests via 
+	birnet_init_settings->test_quick, birnet_init_settings->test_slow and
+	birnet_init_settings->test_perf.
+
+	* tests/sorting.cc:
+	* tests/strings.cc:
+	* tests/threads.cc:
+	* tests/Makefile.am: split up TESTS into SLOWTESTS and PERFTESTS and
+	report performance results properly.
+
 Tue Oct 10 23:23:11 2006  Tim Janik  <timj gtk org>
 
 	* birnetutf8.hh, birnetutf8.cc: added Unichar::isvalid().

Modified: trunk/birnet/birnetcdefs.h
===================================================================
--- trunk/birnet/birnetcdefs.h	2006-10-20 21:09:48 UTC (rev 3992)
+++ trunk/birnet/birnetcdefs.h	2006-10-21 01:51:14 UTC (rev 3993)
@@ -181,6 +181,9 @@
 /* --- initialization --- */
 typedef struct {
   bool stand_alone;		/* "stand-alone": no rcfiles, boot scripts, etc. */
+  bool test_quick;		/* run quick tests */
+  bool test_slow;		/* run slow tests */
+  bool test_perf;		/* run benchmarks, test performance */
 } BirnetInitSettings;
 
 typedef struct {

Modified: trunk/birnet/birnettests.h
===================================================================
--- trunk/birnet/birnettests.h	2006-10-20 21:09:48 UTC (rev 3992)
+++ trunk/birnet/birnettests.h	2006-10-21 01:51:14 UTC (rev 3993)
@@ -67,6 +67,89 @@
 #define TDONE()         do { g_printerr ("]\n"); } while (0)		/* test outro */
 #endif
 
+/* --- performance --- */
+typedef enum {
+  TUNIT_NONE		= 0,
+  TUNIT_PSEC 		= 0xc001,	/* pico second */
+  TUNIT_NSEC 		= 0xd001,	/* nano second */
+  TUNIT_USEC 		= 0xe001,	/* micro second */
+  TUNIT_MSEC 		= 0xf001,	/* milli second */
+  TUNIT_SECOND 		= 0x0001,	/* SECOND */
+  TUNIT_MINUTE 		= 0x1001,
+  TUNIT_HOUR 		= 0x2001,
+  TUNIT_DAY 		= 0x3001,
+  TUNIT_WEEK 		= 0x4001,
+  TUNIT_MONTH 		= 0x5001,
+  TUNIT_YEAR 		= 0x6001,
+  TUNIT_BIT 		= 0x0002,	/* BIT */
+  TUNIT_BYTE 		= 0x0003,	/* BYTE */
+  TUNIT_KILO_BYTE 	= 0x1003,
+  TUNIT_MEGA_BYTE 	= 0x2003,
+  TUNIT_GIGA_BYTE 	= 0x3003,
+  TUNIT_TERA_BYTE 	= 0x4003,
+  TUNIT_STRUCT		= 0x0004,	/* STRUCT */
+  TUNIT_OBJECT		= 0x0005,	/* OBJECT */
+} TUnitType;
+#define	TUNIT(unit1,per_unit2)		((TUnitType) (0x00010000 * (uint) per_unit2 | (uint) unit1))
+
+static const char*
+treport_unit (uint tunit)
+{
+  switch (tunit)
+    {
+    case 0x0000: default: return "";
+    case 0x0001: return "Seconds"; case 0x1001: return "Minutes"; case 0x2001: return "Hours";
+    case 0xc001: return "pSeconds"; case 0xd001: return "nSeconds"; case 0xe001: return "uSeconds"; case 0xf001: return "mSeconds";
+    case 0x3001: return "Days"; case 0x4001: return "Weeks"; case 0x5001: return "Months"; case 0x6001: return "Years";
+    case 0x0002: return "Bits";
+    case 0x0003: return "Bytes"; case 0x1003: return "KBytes"; case 0x2003: return "MBytes"; case 0x3003: return "GBytes"; case 0x4003: return "TBytes";
+    case 0x0004: return "Structs";
+    case 0x0005: return "Objects";
+    };
+}
+static void treport_generic (const char *perf_name, double amount, TUnitType amount_unit, int bias);
+
+static void BIRNET_UNUSED
+treport_title (const char *perf_name)
+{
+  treport_generic (perf_name, 0, TUNIT_NONE, 0);
+}
+static void BIRNET_UNUSED	/* larger amount is better */
+treport_maximized (const char *perf_name,
+		   double      amount,
+		   TUnitType   amount_unit)
+{
+  treport_generic (perf_name, amount, amount_unit, +1);
+}
+static void BIRNET_UNUSED	/* smaller amount is better */
+treport_minimized (const char *perf_name,
+		   double      amount,
+		   TUnitType   amount_unit)
+{
+  treport_generic (perf_name, amount, amount_unit, -1);
+}
+static void	/* smaller amount is better */
+treport_generic (const char *perf_name,
+		 double      amount,
+		 TUnitType   amount_unit,
+		 int         bias)
+{
+  char buffer[64];
+  snprintf (buffer, sizeof (buffer), "%+.14g", amount);
+  int l = strlen (buffer);
+  char *c = strchr (buffer, '.');
+  int n = c ? c - buffer : l;
+  const char spaces[] = "                                             ";
+  uint indent = 8 - MIN (8, n);
+  g_print ("#TBENCH%s: %25s:%s%s%s %s%c%s\n",
+	   bias > 0 ? "=maxi" : bias < 0 ? "=mini" : "=====",
+	   perf_name,
+	   &spaces[sizeof (spaces) - 1 - indent], buffer, &spaces[sizeof (spaces) - 1 - (23 - MIN (23, indent + l))],
+	   treport_unit (amount_unit & 0xffff),
+	   amount_unit > 0xffff ? '/' : ' ',
+	   treport_unit (amount_unit >> 16));
+}
+
 /* --- macro details --- */
 #define TSTART_impl(postfix, ...)	do {		\
   char *_test_name_ = g_strdup_printf (__VA_ARGS__);	\
@@ -158,12 +241,16 @@
   /* normal initialization */
   BirnetInitValue ivalues[] = {
     { "stand-alone", "true" },
+    { "birnet-test-parse-args", "true" },
     { NULL }
   };
   birnet_init (argc, argv, NULL, ivalues);
   unsigned int flags = g_log_set_always_fatal ((GLogLevelFlags) G_LOG_FATAL_MASK);
   g_log_set_always_fatal ((GLogLevelFlags) (flags | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL));
-  g_printerr ("TEST: %s\n", g_get_prgname());
+  if (birnet_init_settings->test_perf)
+    g_printerr ("PERF: %s\n", g_get_prgname());
+  else
+    g_printerr ("TEST: %s\n", g_get_prgname());
 }
 } // Birnet
 #endif

Modified: trunk/birnet/birnetutils.cc
===================================================================
--- trunk/birnet/birnetutils.cc	2006-10-20 21:09:48 UTC (rev 3992)
+++ trunk/birnet/birnetutils.cc	2006-10-21 01:51:14 UTC (rev 3993)
@@ -76,17 +76,72 @@
 const InitSettings *birnet_init_settings = NULL;
 static InitSettings global_init_settings = {
   false,        /* stand_alone */
+  false,        /* perf_test */
 };
 
 static void
-apply_settings_values (InitValue *value)
+birnet_parse_settings_and_args (InitValue *value,
+                                int       *argc_p,
+                                char    ***argv_p)
 {
-  while (value->value_name)
+  bool parse_test_args = false;
+  /* apply settings */
+  if (value)
+    while (value->value_name)
+      {
+        if (strcmp (value->value_name, "stand-alone") == 0)
+          global_init_settings.stand_alone = init_value_bool (value);
+        else if (strcmp (value->value_name, "test-quick") == 0)
+          global_init_settings.test_quick = init_value_bool (value);
+        else if (strcmp (value->value_name, "test-slow") == 0)
+          global_init_settings.test_slow = init_value_bool (value);
+        else if (strcmp (value->value_name, "test-perf") == 0)
+          global_init_settings.test_perf = init_value_bool (value);
+        else if (strcmp (value->value_name, "birnet-test-parse-args") == 0)
+          parse_test_args = init_value_bool (value);
+        value++;
+      }
+  /* parse args */
+  uint argc = *argc_p;
+  char **argv = *argv_p;
+  for (uint i = 1; i < argc; i++)
     {
-      if (strcmp (value->value_name, "stand-alone") == 0)
-        global_init_settings.stand_alone = init_value_bool (value);
-      value++;
+      if (strcmp (argv[i], "--g-fatal-warnings") == 0)
+        {
+          uint fatal_mask = g_log_set_always_fatal (GLogLevelFlags (G_LOG_FATAL_MASK));
+          fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL;
+          g_log_set_always_fatal (GLogLevelFlags (fatal_mask));
+          argv[i] = NULL;
+        }
+      else if (parse_test_args && strcmp ("--test-quick", argv[i]) == 0)
+        {
+          global_init_settings.test_quick = true;
+          argv[i] = NULL;
+        }
+      else if (parse_test_args && strcmp ("--test-slow", argv[i]) == 0)
+        {
+          global_init_settings.test_slow = true;
+          argv[i] = NULL;
+        }
+      else if (parse_test_args && strcmp ("--test-perf", argv[i]) == 0)
+        {
+          global_init_settings.test_perf = true;
+          argv[i] = NULL;
+        }
     }
+  /* fallback handling for tests */
+  if (parse_test_args && !global_init_settings.test_quick && !global_init_settings.test_slow && !global_init_settings.test_perf)
+    global_init_settings.test_quick = true;
+  /* collapse args */
+  uint e = 1;
+  for (uint i = 1; i < argc; i++)
+    if (argv[i])
+      {
+        argv[e++] = argv[i];
+        if (i >= e)
+          argv[i] = NULL;
+      }
+  *argc_p = e;
 }
 
 void
@@ -113,8 +168,7 @@
 
   /* normal initialization */
   birnet_init_settings = &global_init_settings;
-  if (ivalues)
-    apply_settings_values (ivalues);
+  birnet_parse_settings_and_args (ivalues, argcp, argvp);
   if (prg_name)
     g_set_prgname (prg_name);
   g_free (prg_name);

Modified: trunk/birnet/tests/Makefile.am
===================================================================
--- trunk/birnet/tests/Makefile.am	2006-10-20 21:09:48 UTC (rev 3992)
+++ trunk/birnet/tests/Makefile.am	2006-10-21 01:51:14 UTC (rev 3993)
@@ -7,7 +7,6 @@
 INCLUDES       += -I$(top_srcdir) -I$(top_builddir) -I. $(BIRNET_CFLAGS)
 DEFS	       += -DBIRNET_LOG_DOMAIN='"$(basename $(@F))"' -DPARANOID -DG_DISABLE_CONST_RETURNS
 
-TESTS 		 = 
 noinst_PROGRAMS  = $(TESTS)
 progs_ldadd 	 = $(top_builddir)/birnet/libbirnet.o $(BIRNET_LIBS) -lm
 
@@ -15,15 +14,18 @@
 infotest_SOURCES = infotest.cc
 infotest_LDADD	 = $(progs_ldadd)
 TESTS		+= strings
+SLOWTESTS       += strings
 strings_SOURCES  = strings.cc
 strings_LDADD	 = $(progs_ldadd)
 TESTS		+= threads
+PERFTESTS       += threads
 threads_SOURCES	 = threads.cc
 threads_LDADD	 = $(progs_ldadd)
 TESTS		+= signal
 signal_SOURCES	 = signal.cc
 signal_LDADD	 = $(progs_ldadd)
 TESTS		+= sorting
+SLOWTESTS       += sorting
 sorting_SOURCES  = sorting.cc
 sorting_LDADD	 = $(progs_ldadd)
 TESTS		+= datalist

Modified: trunk/birnet/tests/sorting.cc
===================================================================
--- trunk/birnet/tests/sorting.cc	2006-10-20 21:09:48 UTC (rev 3992)
+++ trunk/birnet/tests/sorting.cc	2006-10-21 01:51:14 UTC (rev 3993)
@@ -44,8 +44,9 @@
   vector<float> fv;
   vector<float>::iterator fit;
   std::pair<vector<float>::iterator,bool> pit;
+  const uint count = birnet_init_settings->test_quick ? 90000 : 1000000;
   TSTART ("Corner case lookups");
-  fv.resize (1000000 + (rand() % 10000));
+  fv.resize (count + (rand() % 10000));
   if (fv.size() % 2)
     TACK();
   else

Modified: trunk/birnet/tests/strings.cc
===================================================================
--- trunk/birnet/tests/strings.cc	2006-10-20 21:09:48 UTC (rev 3992)
+++ trunk/birnet/tests/strings.cc	2006-10-21 01:51:14 UTC (rev 3993)
@@ -27,7 +27,7 @@
 random_tf8_and_unichar_test (void)
 {
   TSTART ("utf8<->unichar");
-  const uint count = 1000000;
+  const uint count = birnet_init_settings->test_quick ? 30000 : 1000000;
   for (uint i = 0; i < count; i++)
     {
       if (i % 20000 == 0)
@@ -117,7 +117,7 @@
 random_unichar_test (void)
 {
   TSTART ("unichar classification");
-  const uint count = 1000000;
+  const uint count = birnet_init_settings->test_quick ? 30000 : 1000000;
   for (uint i = 0; i < count; i++)
     {
       unichar uc = rand() % (0x100 << (i % 24));

Modified: trunk/birnet/tests/threads.cc
===================================================================
--- trunk/birnet/tests/threads.cc	2006-10-20 21:09:48 UTC (rev 3992)
+++ trunk/birnet/tests/threads.cc	2006-10-21 01:51:14 UTC (rev 3993)
@@ -785,12 +785,12 @@
   TACK();
   /* done, report */
   TDONE();
-  g_print ("Manual-Locker:      %7.3f nsecs\n", xmin / xdups / RUNS * 1000. * 1000. * 1000.);
-  g_print ("Direct-AutoLocker:  %7.3f nsecs\n", smin / sdups / RUNS * 1000. * 1000. * 1000.);
-  g_print ("Generic-AutoLocker: %7.3f nsecs\n", gmin / gdups / RUNS * 1000. * 1000. * 1000.);
-  g_print ("Birnet-AutoLocker:  %7.3f nsecs\n", bmin / bdups / RUNS * 1000. * 1000. * 1000.);
-  g_print ("Pointer-AutoLocker: %7.3f nsecs\n", pmin / pdups / RUNS * 1000. * 1000. * 1000.);
-  g_print ("Heap-AutoLocker:    %7.3f nsecs\n", tmin / tdups / RUNS * 1000. * 1000. * 1000.);
+  treport_minimized ("Manual-Locker",      xmin / xdups / RUNS * 1000. * 1000. * 1000., TUNIT_NSEC);
+  treport_minimized ("Direct-AutoLocker",  smin / sdups / RUNS * 1000. * 1000. * 1000., TUNIT_NSEC);
+  treport_minimized ("Generic-AutoLocker", gmin / gdups / RUNS * 1000. * 1000. * 1000., TUNIT_NSEC);
+  treport_minimized ("Birnet-AutoLocker",  bmin / bdups / RUNS * 1000. * 1000. * 1000., TUNIT_NSEC);
+  treport_minimized ("Pointer-AutoLocker", pmin / pdups / RUNS * 1000. * 1000. * 1000., TUNIT_NSEC);
+  treport_minimized ("Heap-AutoLocker",    tmin / tdups / RUNS * 1000. * 1000. * 1000., TUNIT_NSEC);
 }
 
 /* --- C++ atomicity tests --- */
@@ -883,12 +883,16 @@
 
   birnet_init_test (&argc, &argv);
 
-  test_threads();
-  test_atomic();
-  test_thread_cxx();
-  test_thread_atomic_cxx();
-  test_auto_locker_cxx();
-  bench_auto_locker_cxx();
+  if (birnet_init_settings->test_quick)
+    {
+      test_threads();
+      test_atomic();
+      test_thread_cxx();
+      test_thread_atomic_cxx();
+      test_auto_locker_cxx();
+    }
+  if (birnet_init_settings->test_perf)
+    bench_auto_locker_cxx();
   
   return 0;
 }




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