summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/util/time.c18
-rw-r--r--lib/util/time.h10
2 files changed, 28 insertions, 0 deletions
diff --git a/lib/util/time.c b/lib/util/time.c
index 05251dd3b5..a09490a198 100644
--- a/lib/util/time.c
+++ b/lib/util/time.c
@@ -652,6 +652,24 @@ _PUBLIC_ double timeval_elapsed(const struct timeval *tv)
struct timeval tv2 = timeval_current();
return timeval_elapsed2(tv, &tv2);
}
+/**
+ * return the number of seconds elapsed between two times
+ **/
+_PUBLIC_ double timespec_elapsed2(const struct timespec *ts1,
+ const struct timespec *ts2)
+{
+ return (ts2->tv_sec - ts1->tv_sec) +
+ (ts2->tv_nsec - ts1->tv_nsec)*1.0e-9;
+}
+
+/**
+ * return the number of seconds elapsed since a given time
+ */
+_PUBLIC_ double timespec_elapsed(const struct timespec *ts)
+{
+ struct timespec ts2 = timespec_current();
+ return timespec_elapsed2(ts, &ts2);
+}
/**
return the lesser of two timevals
diff --git a/lib/util/time.h b/lib/util/time.h
index 69ba783774..b5302f84c2 100644
--- a/lib/util/time.h
+++ b/lib/util/time.h
@@ -247,6 +247,16 @@ double timeval_elapsed2(const struct timeval *tv1, const struct timeval *tv2);
double timeval_elapsed(const struct timeval *tv);
/**
+ return the number of seconds elapsed between two times
+*/
+double timespec_elapsed2(const struct timespec *ts1,
+ const struct timespec *ts2);
+/**
+ return the number of seconds elapsed since a given time
+*/
+double timespec_elapsed(const struct timespec *ts);
+
+/**
return the lesser of two timevals
*/
struct timeval timeval_min(const struct timeval *tv1,