Merge from vendor branch OPENSSL:
[dragonfly.git] / test / sysperf / exec1.c
1 /*
2  * exec1.c
3  *
4  * $DragonFly: src/test/sysperf/exec1.c,v 1.2 2004/04/14 17:59:45 dillon Exp $
5  */
6
7 #include "blib.h"
8 #include <sys/resource.h>
9 #include <sys/wait.h>
10 #include <sys/time.h>
11
12 char *Av0;
13
14 static
15 void
16 execltest(void)
17 {
18     pid_t pid;
19     char *elm;
20
21     if ((elm = strrchr(Av0, '/')) == NULL)
22         elm = Av0;
23     else
24         ++elm;
25
26     if ((pid = vfork()) == 0) {
27         setpriority(PRIO_PROCESS, getpid(), -20);
28         execl(Av0, elm, "dummy", NULL);
29         _exit(1);
30     } else if (pid < 0) {
31         perror("vfork");
32         exit(1);
33     } else {
34         int status;
35
36         while(waitpid(pid, &status, 0) != pid)
37             ;
38         if (WEXITSTATUS(status)) {
39             fprintf(stderr, "execl in child failed\n");
40             exit(1);
41         }
42     }
43 }
44
45 int
46 main(int ac, char **av)
47 {
48     int i;
49     int count;
50
51     Av0 = av[0];
52     if (ac == 2)
53         exit(0);
54
55     count = 0;
56     start_timing();
57     while (stop_timing(0, NULL) == 0) {
58         for (i = 0; i < 100; ++i)
59             execltest();
60         count += 100;
61     }
62     count *= 5;         /* 5 second run */
63     start_timing();
64     for (i = 0; i < count; ++i)
65         execltest();
66 #ifdef ISSTATIC
67     stop_timing(count, "execl static program:", count);
68 #else
69     stop_timing(count, "execl dynamic program:", count);
70 #endif
71     return(0);
72 }
73