2 * from ftp://ftp.netbsd.org/pub/NetBSD/misc/gmcgarry/bench/syscallbench.tar.gz
4 * gcc -Wall -Werror -O3 -static -o ctx ctx.c
14 #define ITERATIONS 500000
19 printf("syscallbench [-h]\n");
23 static int null_func(void)
28 static unsigned long test_func(int (*func
)(void))
30 struct timeval before
, after
;
31 unsigned long elapsed
;
34 gettimeofday(&before
, NULL
);
35 for (i
=0; i
<ITERATIONS
; i
++) {
38 gettimeofday(&after
, NULL
);
40 elapsed
= 1000000 * (after
.tv_sec
- before
.tv_sec
);
41 elapsed
+= after
.tv_usec
- before
.tv_usec
;
46 main(int argc
, char *argv
[])
48 unsigned long overhead
;
49 unsigned long libcall
;
50 unsigned long syscall
;
55 overhead
= test_func(&null_func
);
56 libcall
= test_func((void *)&getpid
); // getpid is currently implemented as a library function returning the value of a global
57 syscall
= test_func((void *)&is_computer_on
);
59 printf("overhead time: %ld nanoseconds\n",
60 (1000*(overhead
))/ITERATIONS
);
62 printf("libcall time: %ld nanoseconds\n",
63 (1000*(libcall
-overhead
))/ITERATIONS
);
65 printf("syscall time: %ld nanoseconds\n",
66 (1000*(syscall
-overhead
))/ITERATIONS
);