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