[gdk-pixbuf/deprecated-timeval: 2/7] Use the monotonic clock instead of wall one



commit ce875584786ff04fea0333af58a0889e2a41ed5f
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Mon Jul 29 18:33:03 2019 +0100

    Use the monotonic clock instead of wall one
    
    We're measuring time deltas; the monotonic clock provides a better
    resolution, and we don't have to care about things like microsecond
    wrap-around or the clock going backwards mid-measurement.

 gdk-pixbuf/pixops/timescale.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)
---
diff --git a/gdk-pixbuf/pixops/timescale.c b/gdk-pixbuf/pixops/timescale.c
index 1a1b59d5d..866e66b8b 100644
--- a/gdk-pixbuf/pixops/timescale.c
+++ b/gdk-pixbuf/pixops/timescale.c
@@ -22,29 +22,23 @@
 
 #include "pixops.h"
 
-static GTimeVal start_time;
+static guint64 start_time;
 
-static void 
+static void
 start_timing (void)
 {
-  g_get_current_time (&start_time);
+  start_time = g_get_monotonic_time ();
 }
 
 static double
 stop_timing (const char *test, int iterations, int bytes)
 {
-  GTimeVal stop_time;
+  guint64 stop_time;
   double msecs;
   
-  g_get_current_time (&stop_time);
-  if (stop_time.tv_usec < start_time.tv_usec)
-    {
-      stop_time.tv_usec += 1000000;
-      stop_time.tv_sec -= 1;
-    }
+  stop_time = g_get_monotonic_time ();
 
-  msecs = (stop_time.tv_sec - start_time.tv_sec) * 1000. +
-          (stop_time.tv_usec - start_time.tv_usec) / 1000.;
+  msecs = (stop_time - start_time) * 1000.0;
 
   printf("%s%d\t%.1f\t\t%.2f\t\t%.2f\n",
         test, iterations, msecs, msecs / iterations, ((double)bytes * iterations) / (1000*msecs));


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