headers/bsd: Add sys/queue.h.
[haiku.git] / src / tests / system / benchmarks / execbench.c
blobe22ca86a88ceb0197a6c39b022cfed1d50b4a308
1 /*
2 * from ftp://ftp.netbsd.org/pub/NetBSD/misc/gmcgarry/bench/execbench.tar.gz
3 */
4 #define errx(x,y...) { fprintf(stderr, y); fprintf(stderr, "\n"); exit(x); }
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <sys/time.h>
9 #include <unistd.h>
11 int
12 main(int argc, char *argv[])
14 struct timeval before, after;
15 unsigned long time, elapsed;
16 char timestr[12], iterstr[12];
17 char *timeptr, *countptr;
18 int iter, count;
20 if (argc < 2)
21 errx(1, "Usage: %s iterations", argv[0]);
23 iter = atoi(argv[1]);
24 if (iter > 0) {
25 gettimeofday(&before, NULL);
26 time = 1000000 * before.tv_sec + before.tv_usec;
27 sprintf(timestr,"%lu", time);
28 timeptr = timestr;
29 countptr = argv[1];
30 } else {
31 iter = atoi(argv[2]);
32 timeptr = argv[3];
33 countptr = argv[4];
36 if (iter != 0) {
37 iter--;
38 sprintf(iterstr, "%d", iter);
39 execl(argv[0], argv[0], "0", iterstr, timeptr, countptr, NULL);
40 errx(1, "execl failed");
43 gettimeofday(&after, NULL);
44 sscanf(argv[3],"%lu", &time);
45 count = atoi(argv[4]);
46 elapsed = 1000000 * after.tv_sec + after.tv_usec;
47 elapsed -= time;
49 printf("time: %lu microseconds\n", elapsed / count);
51 return (1);