Get rid off the POSIX real-time extensions as well as the System V IPC and
[dragonfly.git] / test / sysperf / blib.c
1 /*
2  * BLIB.C
3  *
4  * Simple benchmarking library
5  *
6  * $DragonFly: src/test/sysperf/blib.c,v 1.1 2003/08/12 02:29:44 dillon Exp $
7  */
8
9 #include <sys/types.h>
10 #include <sys/time.h>
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <stdarg.h>
14
15 static struct timeval tv1;
16 static struct timeval tv2;
17
18 void
19 start_timing(void)
20 {
21     gettimeofday(&tv1, NULL);
22 }
23
24 int
25 stop_timing(long long count, const char *ctl, ...)
26 {
27     long long us;
28     va_list va;
29
30     gettimeofday(&tv2, NULL);
31     us = (tv2.tv_usec - tv1.tv_usec) + (tv2.tv_sec - tv1.tv_sec) * 1000000LL;
32     if (ctl == NULL)    /* dummy call to pre-cache */
33         return(us > 1000000);
34
35     va_start(va, ctl);
36     vprintf(ctl, va);
37     va_end(va);
38
39     printf("%6.3fs %lld loops = %6.3fuS/loop\n",
40         (double)us / 1000000.0,
41         count,
42         (double)us / (double)count
43     );
44     return(0);
45 }
46
47 long long
48 get_timing(void)
49 {
50     long long us;
51
52     gettimeofday(&tv2, NULL);
53     us = (tv2.tv_usec - tv1.tv_usec) + (tv2.tv_sec - tv1.tv_sec) * 1000000LL;
54     return(us);
55 }
56