Add high-resolution timekeeping functions (primarily for benchmarking).
[bluesky.git] / bluesky / util.c
index 85f6a70..6a36169 100644 (file)
 
 /* Miscellaneous useful functions that don't really fit anywhere else. */
 
+bluesky_time_hires bluesky_now_hires()
+{
+    struct timespec time;
+
+    if (clock_gettime(CLOCK_REALTIME, &time) != 0) {
+        perror("clock_gettime");
+        return 0;
+    }
+
+    return (int64_t)(time.tv_sec) * 1000000000 + time.tv_nsec;
+}
 
 /* Convert a UTF-8 string to lowercase.  This can be used to implement
  * case-insensitive lookups and comparisons, by normalizing all values to