diff options
author | Emmanuele Bassi <ebassi@gnome.org> | 2019-07-29 18:33:03 +0100 |
---|---|---|
committer | Emmanuele Bassi <ebassi@gnome.org> | 2019-09-08 18:15:39 +0100 |
commit | 57ed7e04a38572c1e1b2329d747ed2ffa4a7cef4 (patch) | |
tree | f8866dbe11a7fc75f4be79c01d751dba5153e187 | |
parent | cd924d5a8589d1262591b056052b8d1c2aed7b63 (diff) | |
download | gdk-pixbuf-57ed7e04a38572c1e1b2329d747ed2ffa4a7cef4.tar.gz |
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.
-rw-r--r-- | gdk-pixbuf/pixops/timescale.c | 18 |
1 files 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)); |