From: Hiten Pandya Date: Wed, 3 Aug 2005 13:37:27 +0000 (+0000) Subject: Add test for comparing following types of conditionals: X-Git-Tag: v2.0.1~6382 X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/commitdiff_plain/a99bca8e35d2d1f023b91e85c040c032f5876917 Add test for comparing following types of conditionals: - comparing a function pointer to NULL from a struct pointer - comparing a function pointer to NULL from a struct - bit-testing --- diff --git a/test/sysperf/Makefile b/test/sysperf/Makefile index 38b89b532e..b65b9702ba 100644 --- a/test/sysperf/Makefile +++ b/test/sysperf/Makefile @@ -1,10 +1,10 @@ # -# $DragonFly: src/test/sysperf/Makefile,v 1.12 2005/08/03 13:29:45 hmp Exp $ +# $DragonFly: src/test/sysperf/Makefile,v 1.13 2005/08/03 13:37:27 hmp Exp $ # TARGETS=/tmp/sc1 /tmp/sc2 /tmp/sc3 /tmp/sc4 /tmp/sc5 \ /tmp/loop1 /tmp/loop2 /tmp/loop3 \ - /tmp/call1 /tmp/call2 /tmp/call3 \ + /tmp/call1 /tmp/call2 /tmp/call3 /tmp/cmp \ /tmp/mt2 \ /tmp/fork1 /tmp/pipe1 /tmp/pipe2 \ /tmp/sw1 /tmp/sw2 /tmp/sw3 \ @@ -64,6 +64,9 @@ all: $(TARGETS) /tmp/call3: call3.c blib.c $(CC) $(CFLAGS) call3.c blib.c -o /tmp/call3 +/tmp/cmp: cmp.c blib.c + $(CC) $(CFLAGS) cmp.c blib.c -o /tmp/cmp + /tmp/mbw1: mbwtest.c $(CC) -O mbwtest.c -o /tmp/mbw1 diff --git a/test/sysperf/cmp.c b/test/sysperf/cmp.c new file mode 100644 index 0000000000..21df2f7889 --- /dev/null +++ b/test/sysperf/cmp.c @@ -0,0 +1,55 @@ +/* + * cmp.c + * + * Test for comparing pointers vs bit-testing. + * + * $DragonFly: src/test/sysperf/cmp.c,v 1.1 2005/08/03 13:37:27 hmp Exp $ + */ + +#include "blib.h" + +#define LOOP 1000000000 + +static void nop(void) { } + +struct f { + void (*nop_ptr)(void); + int mask; +} foo; +#define SOME_MASK 0x00800 + +struct f *fp = &foo; + +int +main(int ac, char **av) +{ + int i; + struct f *fp = &foo; + foo.nop_ptr = nop; + foo.mask = SOME_MASK; + + printf("compare nop() function pointer against NULL (struct not pointer)\n"); + start_timing(); + for (i = 0; i < LOOP; ++i) + if (foo.nop_ptr == NULL) + ; + stop_timing(LOOP, "loop1/cmp-pointer"); + + printf("compare nop() function pointer against NULL (struct pointer)\n"); + start_timing(); + for (i = 0; i < LOOP; ++i) + if (fp->nop_ptr == NULL) + ; + stop_timing(LOOP, "loop2/cmp-pointer"); + + printf("compare bitmask checking\n"); + start_timing(); + for (i = 0; i < LOOP; ++i) + if (foo.mask & SOME_MASK) + ; + stop_timing(LOOP, "loop3/cmp-bitmask"); + + + return(0); +} +