]> Savannah Git Hosting - gnulib.git/commitdiff
mktime: speed up DEBUG_MKTIME benchmarks
authorPaul Eggert <eggert@cs.ucla.edu>
Sun, 1 May 2016 19:49:21 +0000 (12:49 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 2 May 2016 00:27:04 +0000 (17:27 -0700)
Call tzset just once, at the start, rather than for every test
case.  This lets us measure the CPU cost of mktime as opposed to
that of tzset.  This is relevant when TZ is not set and glibc is
being used.  This speeds up tests by a factor of 40 on my Fedora
23 x86-64 platform.
* lib/mktime.c (main) [DEBUG_MKTIME]: Call localtime at the start,
to call tzset and as a sanity check.  Later on, use localtime_r
instead of localtime.

ChangeLog
lib/mktime.c

index 0473a32cb3536350ada7ed30a6cffbe2b37fdb3e..978efec5d90f52c192dbf8abad2c4bc3b11620ff 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2016-05-01  Paul Eggert  <eggert@cs.ucla.edu>
 
+       mktime: speed up DEBUG_MKTIME benchmarks
+       Call tzset just once, at the start, rather than for every test
+       case.  This lets us measure the CPU cost of mktime as opposed to
+       that of tzset.  This is relevant when TZ is not set and glibc is
+       being used.  This speeds up tests by a factor of 40 on my Fedora
+       23 x86-64 platform.
+       * lib/mktime.c (main) [DEBUG_MKTIME]: Call localtime at the start,
+       to call tzset and as a sanity check.  Later on, use localtime_r
+       instead of localtime.
+
        mktime: resurrect DEBUG_MKTIME testing
        * lib/mktime.c [DEBUG_MKTIME]: Do not include <config.h>.
        Include <string.h>, for strcmp.
index 032ea39a94a7ad69f0f32a42e057525e6f49b99d..e3658222a5c78819e573b8c01a1174d12276b3e7 100644 (file)
@@ -600,6 +600,14 @@ main (int argc, char **argv)
   time_t tk, tl, tl1;
   char trailer;
 
+  /* Sanity check, plus call tzset.  */
+  tl = 0;
+  if (! localtime (&tl))
+    {
+      printf ("localtime (0) fails\n");
+      status = 1;
+    }
+
   if ((argc == 3 || argc == 4)
       && (sscanf (argv[1], "%d-%d-%d%c",
                  &tm.tm_year, &tm.tm_mon, &tm.tm_mday, &trailer)
@@ -613,12 +621,7 @@ main (int argc, char **argv)
       tm.tm_isdst = argc == 3 ? -1 : atoi (argv[3]);
       tmk = tm;
       tl = mktime (&tmk);
-      lt = localtime (&tl);
-      if (lt)
-       {
-         tml = *lt;
-         lt = &tml;
-       }
+      lt = localtime_r (&tl, &tml);
       printf ("mktime returns %ld == ", (long int) tl);
       print_tm (&tmk);
       printf ("\n");
@@ -633,16 +636,16 @@ main (int argc, char **argv)
       if (argc == 4)
        for (tl = from; by < 0 ? to <= tl : tl <= to; tl = tl1)
          {
-           lt = localtime (&tl);
+           lt = localtime_r (&tl, &tml);
            if (lt)
              {
-               tmk = tml = *lt;
+               tmk = tml;
                tk = mktime (&tmk);
                status |= check_result (tk, tmk, tl, &tml);
              }
            else
              {
-               printf ("localtime (%ld) yields 0\n", (long int) tl);
+               printf ("localtime_r (%ld) yields 0\n", (long int) tl);
                status = 1;
              }
            tl1 = tl + by;
@@ -653,16 +656,16 @@ main (int argc, char **argv)
        for (tl = from; by < 0 ? to <= tl : tl <= to; tl = tl1)
          {
            /* Null benchmark.  */
-           lt = localtime (&tl);
+           lt = localtime_r (&tl, &tml);
            if (lt)
              {
-               tmk = tml = *lt;
+               tmk = tml;
                tk = tl;
                status |= check_result (tk, tmk, tl, &tml);
              }
            else
              {
-               printf ("localtime (%ld) yields 0\n", (long int) tl);
+               printf ("localtime_r (%ld) yields 0\n", (long int) tl);
                status = 1;
              }
            tl1 = tl + by;