1 #include <ccan/time/time.h>
7 #include "first-approx.c"
10 #include "second-approx.c"
13 #include "no-approx.c"
16 int main(int argc, char *argv[])
18 struct timespec start, val, val2, end, diff;
19 unsigned int i, j, limit = atoi(argv[1] ?: "100000");
22 val = start = time_now();
23 val64 = to_u64(start);
27 for (j = 0; j < limit; j++) {
28 for (i = 0; i < limit; i++) {
29 val = time_add(val, val2);
30 val64 += to_u64(val2);
36 printf("val64 says %lu.%09lu\n",
37 from_u64(val64).tv_sec,
38 from_u64(val64).tv_nsec);
40 printf("val says %lu.%09lu\n",
44 if (time_greater(val, from_u64(val64)))
45 diff = time_sub(val, from_u64(val64));
47 diff = time_sub(from_u64(val64), val);
49 printf("Time %lluns, error = %i%%\n",
50 (long long)time_to_nsec(time_sub(end, start)),
51 (int)(100 * time_to_nsec(diff) / time_to_nsec(time_sub(val, start))));