summaryrefslogtreecommitdiff
path: root/time.cpp
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2020-12-13 14:07:18 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2020-12-13 14:07:18 -0500
commit2146ec5f34e020e4b86e604fdf4859fc55d8f199 (patch)
tree07e2059f7c78e8f1e6e8ca70e47f38477b099e4e /time.cpp
parentb36b0f8fa135beee0a50f16298692c1e076fa9b0 (diff)
fixed NaN bug; show total time
Diffstat (limited to 'time.cpp')
-rw-r--r--time.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/time.cpp b/time.cpp
index fb007ba..3335d66 100644
--- a/time.cpp
+++ b/time.cpp
@@ -17,6 +17,32 @@ static struct timespec time_last_modified(char const *filename) {
#endif
}
+// get the current time. this should only really be used for
+// time intervals, since there's no significance to the absolute number.
+static struct timespec time_get(void) {
+ struct timespec ts = {};
+#if _WIN32
+ FILETIME ft;
+ ULARGE_INTEGER bigint;
+ ULONGLONG t;
+ GetSystemTimeAsFileTime(&ft);
+ bigint.LowPart = ft.dwLowDateTime;
+ bigint.HighPart = ft.dwHighDateTime;
+ t = bigint.QuadPart;
+ ts.tv_sec = t / 10000000;
+ ts.tv_nsec = (t % 10000000) * 100;
+#else
+ clock_gettime(CLOCK_MONOTONIC, &ts);
+#endif
+ return ts;
+}
+
+// subtract timespecs. the return value is seconds.
+static double timespec_sub(struct timespec a, struct timespec b) {
+ return (double)(a.tv_sec - b.tv_sec)
+ + 0.000000001 * (double)(a.tv_nsec - b.tv_nsec);
+}
+
static int timespec_cmp(struct timespec a, struct timespec b) {
if (a.tv_sec > b.tv_sec) return 1;
if (a.tv_sec < b.tv_sec) return -1;