4 * Simple benchmarking library
6 * $DragonFly: src/test/sysperf/blib.c,v 1.6 2007/08/21 19:23:46 corecode Exp $
15 static __thread struct timeval tv1;
16 static __thread struct timeval tv2;
17 static __thread long long last_us;
22 gettimeofday(&tv1, NULL);
26 stop_timing(long long count, const char *ctl, ...)
31 gettimeofday(&tv2, NULL);
32 us = (tv2.tv_usec - tv1.tv_usec) + (tv2.tv_sec - tv1.tv_sec) * 1000000LL;
34 if (ctl == NULL) /* dummy call to pre-cache */
38 vfprintf(stderr, ctl, va);
41 fprintf(stderr, " %6.3fs %lld loops, %8.0f loops/sec, %6.3fuS/loop\n",
42 (double)us / 1000000.0,
44 (double)count * 1e6 / (double)us,
45 (double)us / (double)count
54 stop_timing2(long long count, long long us, const char *ctl, ...)
59 vfprintf(stderr, ctl, va);
62 fprintf(stderr, " %6.3fs %lld loops = %6.3fnS/loop\n",
63 (double)us / 1000000.0,
65 (double)us * 1000.0 / (double)count