vfs: check userland buffers before reading them.
[haiku.git] / src / tests / system / benchmarks / syscallbench.c
blobec9a54856272586c59221eb299289c02b6e0b09a
1 /*
2 * from ftp://ftp.netbsd.org/pub/NetBSD/misc/gmcgarry/bench/syscallbench.tar.gz
4 * gcc -Wall -Werror -O3 -static -o ctx ctx.c
5 */
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <sys/time.h>
10 #include <unistd.h>
12 #include <OS.h>
14 #define ITERATIONS 500000
16 static void
17 usage(void)
19 printf("syscallbench [-h]\n");
20 exit(1);
23 static int null_func(void)
25 return 0;
28 static unsigned long test_func(int (*func)(void))
30 struct timeval before, after;
31 unsigned long elapsed;
32 int i;
34 gettimeofday(&before, NULL);
35 for (i=0; i<ITERATIONS; i++) {
36 func();
38 gettimeofday(&after, NULL);
40 elapsed = 1000000 * (after.tv_sec - before.tv_sec);
41 elapsed += after.tv_usec - before.tv_usec;
42 return elapsed;
45 int
46 main(int argc, char *argv[])
48 unsigned long overhead;
49 unsigned long libcall;
50 unsigned long syscall;
52 if (argc > 1)
53 usage();
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);
68 return (0);