xref: /dragonfly/test/sysperf/cmp.c (revision 548a3528)
1 /*
2  * cmp.c
3  *
4  * Test for comparing pointers vs bit-testing.
5  *
6  * $DragonFly: src/test/sysperf/cmp.c,v 1.1 2005/08/03 13:37:27 hmp Exp $
7  */
8 
9 #include "blib.h"
10 
11 #define LOOP 1000000000
12 
13 static void nop(void) { }
14 
15 struct f {
16 	void (*nop_ptr)(void);
17 	int mask;
18 } foo;
19 #define	SOME_MASK 	0x00800
20 
21 struct f *fp = &foo;
22 
23 int
24 main(int ac, char **av)
25 {
26     int i;
27 	struct f *fp = &foo;
28 	foo.nop_ptr = nop;
29 	foo.mask = SOME_MASK;
30 
31     printf("compare nop() function pointer against NULL (struct not pointer)\n");
32     start_timing();
33     for (i = 0; i < LOOP; ++i)
34 		if (foo.nop_ptr == NULL)
35 			;
36     stop_timing(LOOP, "loop1/cmp-pointer");
37 
38 	printf("compare nop() function pointer against NULL (struct pointer)\n");
39     start_timing();
40     for (i = 0; i < LOOP; ++i)
41 		if (fp->nop_ptr == NULL)
42 			;
43     stop_timing(LOOP, "loop2/cmp-pointer");
44 
45 	printf("compare bitmask checking\n");
46     start_timing();
47     for (i = 0; i < LOOP; ++i)
48 		if (foo.mask & SOME_MASK)
49 			;
50     stop_timing(LOOP, "loop3/cmp-bitmask");
51 
52 
53     return(0);
54 }
55 
56