]> git.ozlabs.org Git - ccan/commitdiff
strset: update ccan/time usage in tools
authorRusty Russell <rusty@rustcorp.com.au>
Tue, 10 Jun 2014 03:36:16 +0000 (13:06 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Tue, 10 Jun 2014 03:36:16 +0000 (13:06 +0930)
Broken since commit 2012d45e273c3016dbd09b2606efc9ffab07c57f
which switched to timespec.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ccan/strset/tools/cbspeed.c
ccan/strset/tools/speed.c

index a1766490341d2acade525dd419ffbd5184e10f3e..3018da9806daec0c404f2c6b245afccd20505c26 100644 (file)
@@ -381,23 +381,17 @@ return allprefixed_traverse(top,handle,arg);
 /* end critbit */
 
 /* Nanoseconds per operation */
 /* end critbit */
 
 /* Nanoseconds per operation */
-static size_t normalize(const struct timeval *start,
-                       const struct timeval *stop,
+static size_t normalize(const struct timespec *start,
+                       const struct timespec *stop,
                        unsigned int num)
 {
                        unsigned int num)
 {
-       struct timeval diff;
-
-       timersub(stop, start, &diff);
-
-       /* Floating point is more accurate here. */
-       return (double)(diff.tv_sec * 1000000 + diff.tv_usec)
-               / num * 1000;
+       return time_to_nsec(time_divide(time_sub(*stop, *start), num));
 }
 
 int main(int argc, char *argv[])
 {
        size_t i, j, num;
 }
 
 int main(int argc, char *argv[])
 {
        size_t i, j, num;
-       struct timeval start, stop;
+       struct timespec start, stop;
        critbit0_tree ct;
        char **words, **misswords;
 
        critbit0_tree ct;
        char **words, **misswords;
 
index 9edb0718bca17fa77b94b118e15166a907baee16..8c815699012208a3ac7d3bad146a10e88c7238c9 100644 (file)
 #include <sys/time.h>
 
 /* Nanoseconds per operation */
 #include <sys/time.h>
 
 /* Nanoseconds per operation */
-static size_t normalize(const struct timeval *start,
-                       const struct timeval *stop,
+static size_t normalize(const struct timespec *start,
+                       const struct timespec *stop,
                        unsigned int num)
 {
                        unsigned int num)
 {
-       struct timeval diff;
-
-       timersub(stop, start, &diff);
-
-       /* Floating point is more accurate here. */
-       return (double)(diff.tv_sec * 1000000 + diff.tv_usec)
-               / num * 1000;
+       return time_to_nsec(time_divide(time_sub(*stop, *start), num));
 }
 
 int main(int argc, char *argv[])
 {
        size_t i, j, num;
 }
 
 int main(int argc, char *argv[])
 {
        size_t i, j, num;
-       struct timeval start, stop;
+       struct timespec start, stop;
        struct strset set;
        char **words, **misswords;
 
        struct strset set;
        char **words, **misswords;