1 | /* $Id: benchmark.c 801 2003-10-04 17:42:15Z bird $ */
|
---|
2 | /** @file
|
---|
3 | *
|
---|
4 | * Benchmark Driver Program
|
---|
5 | *
|
---|
6 | *
|
---|
7 | * Copyright (c) 2001-2003 knut st. osmundsen <bird-srcspam@anduin.net>
|
---|
8 | *
|
---|
9 | *
|
---|
10 | * This program is free software; you can redistribute it and/or modify
|
---|
11 | * it under the terms of the GNU General Public License as published by
|
---|
12 | * the Free Software Foundation; either version 2 of the License, or
|
---|
13 | * (at your option) any later version.
|
---|
14 | *
|
---|
15 | * This program is distributed in the hope that it will be useful,
|
---|
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
18 | * GNU General Public License for more details.
|
---|
19 | *
|
---|
20 | * You should have received a copy of the GNU General Public License
|
---|
21 | * along with This program; if not, write to the Free Software
|
---|
22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
23 | *
|
---|
24 | */
|
---|
25 |
|
---|
26 | /*******************************************************************************
|
---|
27 | * Header Files *
|
---|
28 | *******************************************************************************/
|
---|
29 | #ifdef __OS2__
|
---|
30 | #define INCL_BASE
|
---|
31 | #endif
|
---|
32 | #include <stdio.h>
|
---|
33 | #include <string.h>
|
---|
34 | #include <time.h>
|
---|
35 | #include "PrfTiming.h"
|
---|
36 |
|
---|
37 |
|
---|
38 | /** Number of seconds to sample a testcase where we count iterations. */
|
---|
39 | #define SAMPLE_TIME 3.0
|
---|
40 |
|
---|
41 |
|
---|
42 | /**
|
---|
43 | * Execute pszPgm using CRT methods for executing it.
|
---|
44 | *
|
---|
45 | * @returns Number of childs per minutte.
|
---|
46 | * @returns -1 on failure.
|
---|
47 | * @param pszPgm Program to execute.
|
---|
48 | * @param pszMsg Message to display before doing the execution.
|
---|
49 | */
|
---|
50 | int CrtExecIterate(const char * pszPgm, const char *pszMsg)
|
---|
51 | {
|
---|
52 | long double rdCur;
|
---|
53 | long double rdStart;
|
---|
54 | long double rdEnd;
|
---|
55 | unsigned cChilds;
|
---|
56 | int pid;
|
---|
57 | #ifdef __NOTPC__
|
---|
58 | int status;
|
---|
59 | #endif
|
---|
60 |
|
---|
61 | /*
|
---|
62 | * Message.
|
---|
63 | */
|
---|
64 | if (pszMsg)
|
---|
65 | printf(pszMsg);
|
---|
66 |
|
---|
67 | /*
|
---|
68 | * Main process.
|
---|
69 | */
|
---|
70 | cChilds = 0; /* child count */
|
---|
71 | rdEnd = getHz() * SAMPLE_TIME;
|
---|
72 | rdEnd += rdStart = rdCur = gettime();
|
---|
73 | while (rdEnd > rdCur)
|
---|
74 | {
|
---|
75 | #ifndef __NOTPC__
|
---|
76 | pid = spawnl(P_WAIT, pszPgm, pszPgm, NULL); /* pid == 0 on success */
|
---|
77 | if (pid < 0)
|
---|
78 | {
|
---|
79 | printf("spawnl failed for '%s'\n", pszPgm);
|
---|
80 | return -1;
|
---|
81 | }
|
---|
82 | #else
|
---|
83 | pid = fork();
|
---|
84 | if (pid == 0)
|
---|
85 | {/* child code */
|
---|
86 | execl(pszPgm, pszPgm, NULL);
|
---|
87 | fprintf(stderr, "we should NEVER be here!!\n");
|
---|
88 | return -1;
|
---|
89 | }
|
---|
90 | if (pid > 0)
|
---|
91 | pid = wait(&status);
|
---|
92 | #endif
|
---|
93 | cChilds++;
|
---|
94 | rdCur = gettime();
|
---|
95 | }
|
---|
96 |
|
---|
97 | /*
|
---|
98 | * Result.
|
---|
99 | */
|
---|
100 | cChilds /= ((rdCur - rdStart) / getHz());
|
---|
101 | if (pszMsg)
|
---|
102 | printf("%d childs per second.\n", cChilds);
|
---|
103 |
|
---|
104 | return cChilds;
|
---|
105 | }
|
---|
106 |
|
---|
107 | /**
|
---|
108 | * Execute pszPgm using OS methods for executing it.
|
---|
109 | *
|
---|
110 | * @returns Number of childs per minutte.
|
---|
111 | * @returns -1 on failure.
|
---|
112 | * @param pszPgm Program to execute.
|
---|
113 | * @param pszMsg Message to display before doing the execution.
|
---|
114 | */
|
---|
115 | int OSExecIterate(const char * pszPgm, const char *pszMsg)
|
---|
116 | {
|
---|
117 | long double rdCur;
|
---|
118 | long double rdStart;
|
---|
119 | long double rdEnd;
|
---|
120 | unsigned cChilds;
|
---|
121 | int rc;
|
---|
122 | int pid;
|
---|
123 | #ifdef __NOTPC__
|
---|
124 | int status;
|
---|
125 | #endif
|
---|
126 |
|
---|
127 | /*
|
---|
128 | * Message.
|
---|
129 | */
|
---|
130 | if (pszMsg)
|
---|
131 | printf(pszMsg);
|
---|
132 |
|
---|
133 | /*
|
---|
134 | * Main process.
|
---|
135 | */
|
---|
136 | cChilds = 0; /* child count */
|
---|
137 | rdEnd = getHz() * SAMPLE_TIME;
|
---|
138 | rdEnd += rdStart = rdCur = gettime();
|
---|
139 | while (rdEnd > rdCur)
|
---|
140 | {
|
---|
141 | #ifdef __OS2__
|
---|
142 | RESULTCODES res;
|
---|
143 | rc = DosExecPgm(NULL, 0, EXEC_SYNC, "micro.exe\0", NULL, &res, "micro.exe");
|
---|
144 | if (rc)
|
---|
145 | {
|
---|
146 | printf("failed! (rc=%d)\n", rc);
|
---|
147 | return 1;
|
---|
148 | }
|
---|
149 | #elif defined(__NOTPC__)
|
---|
150 | pid = fork();
|
---|
151 | if (pid == 0)
|
---|
152 | {/* child code */
|
---|
153 | execl(pszPgm, pszPgm, NULL);
|
---|
154 | fprintf(stderr, "we should NEVER be here!!\n");
|
---|
155 | return -1;
|
---|
156 | }
|
---|
157 | if (pid > 0)
|
---|
158 | pid = wait(&status);
|
---|
159 | #else
|
---|
160 | #error "Not ported to this OS."
|
---|
161 | #endif
|
---|
162 | cChilds++;
|
---|
163 | rdCur = gettime();
|
---|
164 | }
|
---|
165 |
|
---|
166 | /*
|
---|
167 | * Result.
|
---|
168 | */
|
---|
169 | cChilds /= ((rdCur - rdStart) / getHz());
|
---|
170 | if (pszMsg)
|
---|
171 | printf("%d childs per second.\n", cChilds);
|
---|
172 |
|
---|
173 | return cChilds;
|
---|
174 | }
|
---|
175 |
|
---|
176 |
|
---|
177 |
|
---|
178 | int main(int argc, char **argv)
|
---|
179 | {
|
---|
180 | setvbuf(stdout, NULL, _IONBF, 0); /* no buffering. */
|
---|
181 |
|
---|
182 | /*
|
---|
183 | * Output some general stuff about this box.
|
---|
184 | */
|
---|
185 | printf("LIBC Benchmark v0.0.0\n");
|
---|
186 | printSystemInfo();
|
---|
187 |
|
---|
188 | /*
|
---|
189 | * Do calibration.
|
---|
190 | */
|
---|
191 | OSExecIterate( "micro", "Calibration OS... ");
|
---|
192 | CrtExecIterate("micro", "Calibration CRT... ");
|
---|
193 |
|
---|
194 | /*
|
---|
195 | * Do startup time tests.
|
---|
196 | */
|
---|
197 | CrtExecIterate("startup1-static", "Startup - bare, static: \t");
|
---|
198 | CrtExecIterate("startup1-dynamic", "Startup - bare, dynamic: \t");
|
---|
199 |
|
---|
200 | return 0;
|
---|
201 | }
|
---|