add tutil_tvdiff_secs() for completeness
authorYang Tse <yangsita@gmail.com>
Tue, 20 Feb 2007 01:09:38 +0000 (01:09 +0000)
committerYang Tse <yangsita@gmail.com>
Tue, 20 Feb 2007 01:09:38 +0000 (01:09 +0000)
tests/libtest/testutil.c
tests/libtest/testutil.h

index 6acd5a71b9457a5a25b2d64128669c62d5a836c2..dc0211026478d2fcc1f1f0740789a07a7654f89d 100644 (file)
@@ -98,6 +98,17 @@ long tutil_tvdiff(struct timeval newer, struct timeval older)
     (newer.tv_usec-older.tv_usec)/1000;
 }
 
+/*
+ * Same as tutil_tvdiff but with full usec resolution.
+ *
+ * Returns: the time difference in seconds with subsecond resolution.
+ */
+double tutil_tvdiff_secs(struct timeval newer, struct timeval older)
+{
+  return (double)(newer.tv_sec-older.tv_sec)+
+    (double)(newer.tv_usec-older.tv_usec)/1000000.0;
+}
+
 /* return the number of seconds in the given input timeval struct */
 long tutil_tvlong(struct timeval t1)
 {
index 18bd9e99ccb1a5031189f3ffc5e0ba245720c70b..e248c1ebe7c0f43f04c5669ab6586bcf6d4f35fa 100644 (file)
@@ -56,6 +56,13 @@ struct timeval tutil_tvnow(void);
  */
 long tutil_tvdiff(struct timeval t1, struct timeval t2);
 
+/*
+ * Same as tutil_tvdiff but with full usec resolution.
+ *
+ * Returns: the time difference in seconds with subsecond resolution.
+ */
+double tutil_tvdiff_secs(struct timeval t1, struct timeval t2);
+
 long tutil_tvlong(struct timeval t1);