Changeset: 4bf7d21f57fb for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=4bf7d21f57fb
Modified Files:
        configure.ag
        gdk/gdk_system.c
Branch: Dec2016
Log Message:

Use a potentially faster method of asking for the time.

GDKusec() is used to get some measure of how much time was spent since
some epoch.  Using clock_gettime instead of gettimeofday significantly
boosts performance on FreeBSD and does no harm on Linux.


diffs (70 lines):

diff --git a/configure.ag b/configure.ag
--- a/configure.ag
+++ b/configure.ag
@@ -2543,6 +2543,7 @@ LIBS="$LIBS $MATH_LIBS"
 AC_CHECK_FUNCS([\
        asctime_r \
        backtrace \
+       clock_gettime \
        ctime_r \
        fabsf \
        fallocate \
diff --git a/gdk/gdk_system.c b/gdk/gdk_system.c
--- a/gdk/gdk_system.c
+++ b/gdk/gdk_system.c
@@ -895,16 +895,36 @@ GDKusec(void)
                return (lng) (((ctr.QuadPart - start.QuadPart) * 1000000) / 
freq.QuadPart);
        }
 #endif
+#ifdef HAVE_CLOCK_GETTIME
+#if defined(CLOCK_UPTIME_FAST)
+#define CLK_ID CLOCK_UPTIME_FAST       /* FreeBSD */
+#elif defined(CLOCK_MONOTONIC_COARSE)
+#define CLK_ID CLOCK_MONOTONIC_COARSE  /* Linux >= 2.6.32 */
+#else
+#define CLK_ID CLOCK_MONOTONIC         /* Posix (fallback) */
+#endif
+       {
+               static struct timespec tsbase;
+               struct timespec ts;
+               if (tsbase.tv_sec == 0) {
+                       clock_gettime(CLK_ID, &tsbase);
+                       return tsbase.tv_nsec / 1000;
+               }
+               if (clock_gettime(CLK_ID, &ts) == 0)
+                       return (ts.tv_sec - tsbase.tv_sec) * 1000000 + 
ts.tv_nsec / 1000;
+       }
+#endif
 #ifdef HAVE_GETTIMEOFDAY
        {
                static struct timeval tpbase;   /* automatically initialized to 
0 */
                struct timeval tp;
 
-               if (tpbase.tv_sec == 0)
+               if (tpbase.tv_sec == 0) {
                        gettimeofday(&tpbase, NULL);
+                       return (lng) tpbase.tv_usec;
+               }
                gettimeofday(&tp, NULL);
-               tp.tv_sec -= tpbase.tv_sec;
-               return (lng) tp.tv_sec * 1000000 + (lng) tp.tv_usec;
+               return (lng) (tp.tv_sec - tpbase.tv_sec) * 1000000 + (lng) 
tp.tv_usec;
        }
 #else
 #ifdef HAVE_FTIME
@@ -912,11 +932,12 @@ GDKusec(void)
                static struct timeb tbbase;     /* automatically initialized to 
0 */
                struct timeb tb;
 
-               if (tbbase.time == 0)
+               if (tbbase.time == 0) {
                        ftime(&tbbase);
+                       return (lng) tbbase.millitm * 1000;
+               }
                ftime(&tb);
-               tb.time -= tbbase.time;
-               return (lng) tb.time * 1000000 + (lng) tb.millitm * 1000;
+               return (lng) (tb.time - tbbase.time) * 1000000 + (lng) 
tb.millitm * 1000;
        }
 #endif
 #endif
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to