2 * from ftp://ftp.netbsd.org/pub/NetBSD/misc/gmcgarry/bench/forkbench.tar.gz
5 /* From 4.4 BSD sys/tests/benchmarks/forks.c. */
14 * Benchmark program to calculate fork+wait
15 * overhead (approximately). Process
16 * forks and exits while parent waits.
17 * The time to run this program is used
18 * in calculating exec overhead.
27 int pid
, child
, status
, brksize
;
28 struct timeval before
, after
;
32 printf("usage: %s number-of-forks sbrk-size\n", argv
[0]);
35 nforks
= atoi(argv
[1]);
37 printf("%s: bad number of forks\n", argv
[1]);
40 brksize
= atoi(argv
[2]);
42 printf("%s: bad size to sbrk\n", argv
[2]);
46 gettimeofday(&before
, NULL
);
47 cp
= (char *)sbrk(brksize
);
48 if (cp
== (void *)-1) {
52 for (i
= 0; i
< brksize
; i
+= 1024)
54 for (i
=0; i
<nforks
; i
++) {
62 while ((pid
= wait(&status
)) != -1 && pid
!= child
)
65 gettimeofday(&after
, NULL
);
66 elapsed
= 1000000 * (after
.tv_sec
- before
.tv_sec
);
67 elapsed
+= (after
.tv_usec
- before
.tv_usec
);
68 printf ("Time: %d microseconds.\n", elapsed
/nforks
);