source: trunk/minix/commands/simple/dhrystone.c@ 9

Last change on this file since 9 was 9, checked in by Mattia Monga, 13 years ago

Minix 3.1.2a

File size: 12.5 KB
Line 
1/* dhrystone - benchmark program */
2
3#define REGISTER
4/*
5 *
6 * "DHRYSTONE" Benchmark Program
7 *
8 * Version: C/1.1, 12/01/84
9 *
10 * Date: PROGRAM updated 01/06/86, COMMENTS changed 01/31/87
11 *
12 * Author: Reinhold P. Weicker, CACM Vol 27, No 10, 10/84 pg.1013
13 * Translated from ADA by Rick Richardson
14 * Every method to preserve ADA-likeness has been used,
15 * at the expense of C-ness.
16 *
17 * Compile: cc -O dry.c -o drynr : No registers
18 * cc -O -DREG=register dry.c -o dryr : Registers
19 *
20 * Defines: Defines are provided for old C compiler's
21 * which don't have enums, and can't assign structures.
22 * The time(2) function is library dependant; Most
23 * return the time in seconds, but beware of some, like
24 * Aztec C, which return other units.
25 * The LOOPS define is initially set for 50000 loops.
26 * If you have a machine with large integers and is
27 * very fast, please change this number to 500000 to
28 * get better accuracy. Please select the way to
29 * measure the execution time using the TIME define.
30 * For single user machines, time(2) is adequate. For
31 * multi-user machines where you cannot get single-user
32 * access, use the times(2) function. Be careful to
33 * adjust the HZ parameter below for the units which
34 * are returned by your times(2) function. You can
35 * sometimes find this in <sys/param.h>. If you have
36 * neither time(2) nor times(2), use a stopwatch in
37 * the dead of the night.
38 * Use a "printf" at the point marked "start timer"
39 * to begin your timings. DO NOT use the UNIX "time(1)"
40 * command, as this will measure the total time to
41 * run this program, which will (erroneously) include
42 * the time to malloc(3) storage and to compute the
43 * time it takes to do nothing.
44 *
45 * Run: drynr; dryr
46 *
47 * Results: If you get any new machine/OS results, please send to:
48 *
49 * ihnp4!castor!pcrat!rick
50 *
51 * and thanks to all that do.
52 *
53 * Note: I order the list in increasing performance of the
54 * "with registers" benchmark. If the compiler doesn't
55 * provide register variables, then the benchmark
56 * is the same for both REG and NOREG.
57 *
58 * PLEASE: Send complete information about the machine type,
59 * clock speed, OS and C manufacturer/version. If
60 * the machine is modified, tell me what was done.
61 * On UNIX, execute uname -a and cc -V to get this info.
62 *
63 * 80x8x NOTE: 80x8x benchers: please try to do all memory models
64 * for a particular compiler.
65 *
66 *
67 * The following program contains statements of a high-level programming
68 * language (C) in a distribution considered representative:
69 *
70 * assignments 53%
71 * control statements 32%
72 * procedure, function calls 15%
73 *
74 * 100 statements are dynamically executed. The program is balanced with
75 * respect to the three aspects:
76 * - statement type
77 * - operand type (for simple data types)
78 * - operand access
79 * operand global, local, parameter, or constant.
80 *
81 * The combination of these three aspects is balanced only approximately.
82 *
83 * The program does not compute anything meaningfull, but it is
84 * syntactically and semantically correct.
85 *
86 */
87
88
89#include <sys/types.h>
90#include <stdlib.h>
91#include <string.h>
92#include <time.h>
93#include <stdio.h>
94#include <signal.h>
95#include <unistd.h>
96
97/* Accuracy of timings and human fatigue controlled by next two lines */
98/*#define LOOPS 50000 */ /* Use this for slow or 16 bit machines */
99/*#define LOOPS 500000 */ /* Use this for faster machines */
100/*#define LOOPS (sizeof(int) == 2 ? 50000 : 1000000)*/
101
102/* Seconds to run */
103#define SECONDS 15
104
105/* Compiler dependent options */
106#define NOENUM /* Define if compiler has no enum's */
107/* #define NOSTRUCTASSIGN */ /* Define if compiler can't assign structures*/
108
109
110/* Define only one of the next two defines */
111#define TIMES /* Use times(2) time function */
112/*#define TIME */ /* Use time(2) time function */
113
114
115#ifdef TIME
116/* Ganularity of time(2) is of course 1 second */
117#define HZ 1
118#endif
119
120#ifdef TIMES
121/* Define the granularity of your times(2) function */
122/*#define HZ 50 */ /* times(2) returns 1/50 second (europe?) */
123/*#define HZ 60 */ /* times(2) returns 1/60 second (most) */
124/*#define HZ 100 */ /* times(2) returns 1/100 second (WECo) */
125#endif
126
127/* For compatibility with goofed up version */
128/*#undef GOOF */ /* Define if you want the goofed up version */
129
130
131#ifdef GOOF
132char Version[] = "1.0";
133#else
134char Version[] = "1.1";
135#endif
136
137
138#ifdef NOSTRUCTASSIGN
139#define structassign(d, s) memcpy(&(d), &(s), sizeof(d))
140#else
141#define structassign(d, s) d = s
142#endif
143
144
145#ifdef NOENUM
146#define Ident1 1
147#define Ident2 2
148#define Ident3 3
149#define Ident4 4
150#define Ident5 5
151typedef int Enumeration;
152#else
153typedef enum {
154 Ident1, Ident2, Ident3, Ident4, Ident5
155} Enumeration;
156#endif
157
158typedef int OneToThirty;
159typedef int OneToFifty;
160typedef char CapitalLetter;
161typedef char String30[31];
162typedef int Array1Dim[51];
163typedef int Array2Dim[51][51];
164
165struct Record {
166 struct Record *PtrComp;
167 Enumeration Discr;
168 Enumeration EnumComp;
169 OneToFifty IntComp;
170 String30 StringComp;
171};
172
173typedef struct Record RecordType;
174typedef RecordType *RecordPtr;
175typedef int boolean;
176
177#ifdef NULL
178#undef NULL
179#endif
180
181#define NULL 0
182#define TRUE 1
183#define FALSE 0
184
185#ifndef REG
186#define REG
187#endif
188
189
190#ifdef TIMES
191#include <sys/times.h>
192#endif
193
194#ifndef _PROTOTYPE
195#define _PROTOTYPE(fun, args) fun args
196#endif
197
198_PROTOTYPE(int main, (void));
199_PROTOTYPE(void prep_timer, (void));
200_PROTOTYPE(void timeout, (int sig));
201_PROTOTYPE(void Proc0, (void));
202_PROTOTYPE(void Proc1, (RecordPtr PtrParIn));
203_PROTOTYPE(void Proc2, (OneToFifty *IntParIO));
204_PROTOTYPE(void Proc3, (RecordPtr *PtrParOut));
205_PROTOTYPE(void Proc4, (void));
206_PROTOTYPE(void Proc5, (void));
207_PROTOTYPE(void Proc6, (Enumeration EnumParIn, Enumeration *EnumParOut));
208_PROTOTYPE(void Proc7, (OneToFifty IntParI1, OneToFifty IntParI2,
209 OneToFifty *IntParOut));
210_PROTOTYPE(void Proc8, (Array1Dim Array1Par, Array2Dim Array2Par,
211 OneToFifty IntParI1, OneToFifty IntParI2));
212/*_PROTOTYPE(Enumeration Func1,(CapitalLetter CharPar1, CapitalLetter CharPar2));*/
213_PROTOTYPE(boolean Func2, (String30 StrParI1, String30 StrParI2));
214_PROTOTYPE(boolean Func3, (Enumeration EnumParIn));
215
216_PROTOTYPE(Enumeration Func1, (int CharPar1, int CharPar2));
217
218
219int main()
220{
221 Proc0();
222 return(0);
223}
224
225
226#if __STDC__
227volatile int done;
228#else
229int done;
230#endif
231
232void prep_timer()
233{
234 signal(SIGALRM, timeout);
235 done = 0;
236}
237
238void timeout(sig)
239int sig;
240{
241 done = 1;
242}
243
244/* Package 1 */
245int IntGlob;
246boolean BoolGlob;
247char Char1Glob;
248char Char2Glob;
249Array1Dim Array1Glob;
250Array2Dim Array2Glob;
251RecordPtr PtrGlb;
252RecordPtr PtrGlbNext;
253
254
255void Proc0()
256{
257 OneToFifty IntLoc1;
258 REG OneToFifty IntLoc2;
259 OneToFifty IntLoc3;
260 REG char CharIndex;
261 Enumeration EnumLoc;
262 String30 String1Loc;
263 String30 String2Loc;
264 register unsigned long i;
265 unsigned long starttime;
266 unsigned long benchtime;
267 unsigned long nulltime;
268 unsigned long nullloops;
269 unsigned long benchloops;
270 unsigned long ticks_per_sec;
271#ifdef TIMES
272 struct tms tms;
273#endif
274
275#ifdef HZ
276#define ticks_per_sec HZ
277#else
278 ticks_per_sec = sysconf(_SC_CLK_TCK);
279#endif
280
281 i = 0;
282 prep_timer();
283
284#ifdef TIME
285 starttime = time((long *) 0);
286#endif
287
288#ifdef TIMES
289 times(&tms);
290 starttime = tms.tms_utime;
291#endif
292
293 alarm(1);
294 while (!done) i++;
295
296#ifdef TIME
297 nulltime = time((long *) 0) - starttime; /* Computes o'head of loop */
298#endif
299
300#ifdef TIMES
301 times(&tms);
302 nulltime = tms.tms_utime - starttime; /* Computes overhead of looping */
303#endif
304
305 nullloops = i;
306
307
308 PtrGlbNext = (RecordPtr) malloc(sizeof(RecordType));
309 PtrGlb = (RecordPtr) malloc(sizeof(RecordType));
310 PtrGlb->PtrComp = PtrGlbNext;
311 PtrGlb->Discr = Ident1;
312 PtrGlb->EnumComp = Ident3;
313 PtrGlb->IntComp = 40;
314 strcpy(PtrGlb->StringComp, "DHRYSTONE PROGRAM, SOME STRING");
315#ifndef GOOF
316 strcpy(String1Loc, "DHRYSTONE PROGRAM, 1'ST STRING"); /* GOOF */
317#endif
318
319 Array2Glob[8][7] = 10; /* Was missing in published program */
320
321
322/*****************
323-- Start Timer --
324*****************/
325 i = 0;
326 prep_timer();
327
328#ifdef TIME
329 starttime = time((long *) 0);
330#endif
331
332#ifdef TIMES
333 times(&tms);
334 starttime = tms.tms_utime;
335#endif
336
337 alarm(SECONDS);
338 while (!done) {
339 i++;
340 Proc5();
341 Proc4();
342 IntLoc1 = 2;
343 IntLoc2 = 3;
344 strcpy(String2Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
345 EnumLoc = Ident2;
346 BoolGlob = !Func2(String1Loc, String2Loc);
347 while (IntLoc1 < IntLoc2) {
348 IntLoc3 = 5 * IntLoc1 - IntLoc2;
349 Proc7(IntLoc1, IntLoc2, &IntLoc3);
350 ++IntLoc1;
351 }
352 Proc8(Array1Glob, Array2Glob, IntLoc1, IntLoc3);
353 Proc1(PtrGlb);
354 for (CharIndex = 'A'; CharIndex <= Char2Glob; ++CharIndex)
355 if (EnumLoc == Func1(CharIndex, 'C'))
356 Proc6(Ident1, &EnumLoc);
357 IntLoc3 = IntLoc2 * IntLoc1;
358 IntLoc2 = IntLoc3 / IntLoc1;
359 IntLoc2 = 7 * (IntLoc3 - IntLoc2) - IntLoc1;
360 Proc2(&IntLoc1);
361 }
362
363
364/*****************
365-- Stop Timer --
366*****************/
367
368
369#ifdef TIME
370 benchtime = time((long *) 0) - starttime;
371#endif
372
373#ifdef TIMES
374 times(&tms);
375 benchtime = tms.tms_utime - starttime;
376#endif
377 benchloops = i;
378
379 /* Approximately correct benchtime to the nulltime. */
380 benchtime -= nulltime / (nullloops / benchloops);
381
382 printf("Dhrystone(%s) time for %lu passes = %lu.%02lu\n",
383 Version,
384 benchloops, benchtime / ticks_per_sec,
385 benchtime % ticks_per_sec * 100 / ticks_per_sec);
386 printf("This machine benchmarks at %lu dhrystones/second\n",
387 benchloops * ticks_per_sec / benchtime);
388}
389
390
391void Proc1(PtrParIn)
392REG RecordPtr PtrParIn;
393{
394#define NextRecord (*(PtrParIn->PtrComp))
395
396
397 structassign(NextRecord, *PtrGlb);
398 PtrParIn->IntComp = 5;
399 NextRecord.IntComp = PtrParIn->IntComp;
400 NextRecord.PtrComp = PtrParIn->PtrComp;
401 Proc3((RecordPtr *)NextRecord.PtrComp);
402 if (NextRecord.Discr == Ident1) {
403 NextRecord.IntComp = 6;
404 Proc6(PtrParIn->EnumComp, &NextRecord.EnumComp);
405 NextRecord.PtrComp = PtrGlb->PtrComp;
406 Proc7(NextRecord.IntComp, 10, &NextRecord.IntComp);
407 } else
408 structassign(*PtrParIn, NextRecord);
409
410
411#undef NextRecord
412}
413
414
415void Proc2(IntParIO)
416OneToFifty *IntParIO;
417{
418 REG OneToFifty IntLoc;
419 REG Enumeration EnumLoc;
420
421
422 IntLoc = *IntParIO + 10;
423 for (;;) {
424 if (Char1Glob == 'A') {
425 --IntLoc;
426 *IntParIO = IntLoc - IntGlob;
427 EnumLoc = Ident1;
428 }
429 if (EnumLoc == Ident1) break;
430 }
431}
432
433
434void Proc3(PtrParOut)
435RecordPtr *PtrParOut;
436{
437 if (PtrGlb != NULL)
438 *PtrParOut = PtrGlb->PtrComp;
439 else
440 IntGlob = 100;
441 Proc7(10, IntGlob, &PtrGlb->IntComp);
442}
443
444
445void Proc4()
446{
447 REG boolean BoolLoc;
448
449
450 BoolLoc = Char1Glob == 'A';
451 BoolLoc |= BoolGlob;
452 Char2Glob = 'B';
453}
454
455
456void Proc5()
457{
458 Char1Glob = 'A';
459 BoolGlob = FALSE;
460}
461
462
463void Proc6(EnumParIn, EnumParOut)
464REG Enumeration EnumParIn;
465REG Enumeration *EnumParOut;
466{
467 *EnumParOut = EnumParIn;
468 if (!Func3(EnumParIn)) *EnumParOut = Ident4;
469 switch (EnumParIn) {
470 case Ident1: *EnumParOut = Ident1; break;
471 case Ident2:
472 if (IntGlob > 100)
473 *EnumParOut = Ident1;
474 else
475 *EnumParOut = Ident4;
476 break;
477 case Ident3: *EnumParOut = Ident2; break;
478 case Ident4:
479 break;
480 case Ident5: *EnumParOut = Ident3;
481}
482}
483
484
485void Proc7(IntParI1, IntParI2, IntParOut)
486OneToFifty IntParI1;
487OneToFifty IntParI2;
488OneToFifty *IntParOut;
489{
490 REG OneToFifty IntLoc;
491
492
493 IntLoc = IntParI1 + 2;
494 *IntParOut = IntParI2 + IntLoc;
495}
496
497
498void Proc8(Array1Par, Array2Par, IntParI1, IntParI2)
499Array1Dim Array1Par;
500Array2Dim Array2Par;
501OneToFifty IntParI1;
502OneToFifty IntParI2;
503{
504 REG OneToFifty IntLoc;
505 REG OneToFifty IntIndex;
506
507
508 IntLoc = IntParI1 + 5;
509 Array1Par[IntLoc] = IntParI2;
510 Array1Par[IntLoc + 1] = Array1Par[IntLoc];
511 Array1Par[IntLoc + 30] = IntLoc;
512 for (IntIndex = IntLoc; IntIndex <= (IntLoc + 1); ++IntIndex)
513 Array2Par[IntLoc][IntIndex] = IntLoc;
514 ++Array2Par[IntLoc][IntLoc - 1];
515 Array2Par[IntLoc + 20][IntLoc] = Array1Par[IntLoc];
516 IntGlob = 5;
517}
518
519
520Enumeration Func1(CharPar1, CharPar2)
521CapitalLetter CharPar1;
522CapitalLetter CharPar2;
523{
524 REG CapitalLetter CharLoc1;
525 REG CapitalLetter CharLoc2;
526
527
528 CharLoc1 = CharPar1;
529 CharLoc2 = CharLoc1;
530 if (CharLoc2 != CharPar2)
531 return(Ident1);
532 else
533 return(Ident2);
534}
535
536
537boolean Func2(StrParI1, StrParI2)
538String30 StrParI1;
539String30 StrParI2;
540{
541 REG OneToThirty IntLoc;
542 REG CapitalLetter CharLoc;
543
544
545 IntLoc = 1;
546 while (IntLoc <= 1)
547 if (Func1(StrParI1[IntLoc], StrParI2[IntLoc + 1]) == Ident1) {
548 CharLoc = 'A';
549 ++IntLoc;
550 }
551 if (CharLoc >= 'W' && CharLoc <= 'Z') IntLoc = 7;
552 if (CharLoc == 'X')
553 return(TRUE);
554 else {
555 if (strcmp(StrParI1, StrParI2) > 0) {
556 IntLoc += 7;
557 return(TRUE);
558 } else
559 return(FALSE);
560 }
561}
562
563
564boolean Func3(EnumParIn)
565REG Enumeration EnumParIn;
566{
567 REG Enumeration EnumLoc;
568
569
570 EnumLoc = EnumParIn;
571 if (EnumLoc == Ident3) return(TRUE);
572 return(FALSE);
573}
574
575
576#ifdef NOSTRUCTASSIGN
577memcpy(d, s, l)
578register char *d;
579register char *s;
580register int l;
581{
582 while (l--) *d++ = *s++;
583}
584
585#endif
Note: See TracBrowser for help on using the repository browser.