Add test for comparing following types of conditionals:
authorHiten Pandya <hmp@dragonflybsd.org>
Wed, 3 Aug 2005 13:37:27 +0000 (13:37 +0000)
committerHiten Pandya <hmp@dragonflybsd.org>
Wed, 3 Aug 2005 13:37:27 +0000 (13:37 +0000)
 - comparing a function pointer to NULL from a struct pointer
 - comparing a function pointer to NULL from a struct
 - bit-testing

test/sysperf/Makefile
test/sysperf/cmp.c [new file with mode: 0644]

index 38b89b5..b65b970 100644 (file)
@@ -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 (file)
index 0000000..21df2f7
--- /dev/null
@@ -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);
+}
+