2 *************************************************************************
4 * "DHRYSTONE" Benchmark Program
5 * -----------------------------
7 * Version: C, Version 2.1
9 * File: dhry_1.c (part 2 of 3)
13 * Author: Reinhold P. Weicker
15 *************************************************************************
22 /*COMPILER COMPILER COMPILER COMPILER COMPILER COMPILER COMPILER*/
25 #define compiler "Watcom C/C++ 10.5 Win386"
26 #define options " -otexan -zp8 -5r -ms"
29 #define compiler "Watcom C/C++ 10.5 Win386"
30 #define options " No optimisation"
33 #define compiler "Watcom C/C++ 10.5 Dos4GW"
34 #define options " -otexan -zp8 -5r -ms"
37 #define compiler "Watcom C/C++ 10.5 Dos4GW"
38 #define options " No optimisation"
41 #define compiler "Watcom C/C++ 10.5 Win32NT"
42 #define options " -otexan -zp8 -5r -ms"
45 #define compiler "Watcom C/C++ 10.5 Win32NT"
46 #define options " No optimisation"
49 #define compiler "Watcom C/C++ 10.5 OS/2-32"
50 #define options " -otexan -zp8 -5r -ms"
53 #define compiler "Watcom C/C++ 10.5 OS/2-32"
54 #define options " No optimisation"
58 /* Global Variables: */
67 int Arr_2_Glob [50] [50];
71 char Reg_Define[100] = "Register option Selected.";
73 Enumeration Func_1 (Capital_Letter Ch_1_Par_Val,
74 Capital_Letter Ch_2_Par_Val);
76 forward declaration necessary since Enumeration may not simply be int
81 /* REG becomes defined as empty */
82 /* i.e. no register variables */
87 void Proc_1 (REG Rec_Pointer Ptr_Val_Par);
88 void Proc_2 (One_Fifty *Int_Par_Ref);
89 void Proc_3 (Rec_Pointer *Ptr_Ref_Par);
92 void Proc_6 (Enumeration Enum_Val_Par, Enumeration *Enum_Ref_Par);
93 void Proc_7 (One_Fifty Int_1_Par_Val, One_Fifty Int_2_Par_Val,
94 One_Fifty *Int_Par_Ref);
95 void Proc_8 (Arr_1_Dim Arr_1_Par_Ref, Arr_2_Dim Arr_2_Par_Ref,
96 int Int_1_Par_Val, int Int_2_Par_Val);
98 Boolean Func_2 (Str_30 Str_1_Par_Ref, Str_30 Str_2_Par_Ref);
101 /* variables for time measurement: */
103 #define Too_Small_Time 2
104 /* Measurements should last at least 2 seconds */
111 Dhrystones_Per_Second,
114 /* end of variables for time measurement */
117 void main (int argc, char *argv[])
120 /* main program, corresponds to procedures */
121 /* Main and Proc_0 in the Ada version */
126 REG One_Fifty Int_2_Loc;
129 Enumeration Enum_Loc;
133 REG int Number_Of_Runs;
134 int endit, count = 10;
136 char general[9][80] = {" "};
138 /* Initializations */
152 if ((Ap = fopen("Dhry.txt","a+")) == NULL)
154 printf("Can not open Dhry.txt\n\n");
155 printf("Press any key\n");
159 /***********************************************************************
160 * Change for compiler and optimisation used *
161 ***********************************************************************/
163 Next_Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
164 Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
166 Ptr_Glob->Ptr_Comp = Next_Ptr_Glob;
167 Ptr_Glob->Discr = Ident_1;
168 Ptr_Glob->variant.var_1.Enum_Comp = Ident_3;
169 Ptr_Glob->variant.var_1.Int_Comp = 40;
170 strcpy (Ptr_Glob->variant.var_1.Str_Comp,
171 "DHRYSTONE PROGRAM, SOME STRING");
172 strcpy (Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING");
174 Arr_2_Glob [8][7] = 10;
175 /* Was missing in published program. Without this statement, */
176 /* Arr_2_Glob [8][7] would have an undefined value. */
177 /* Warning: With 16-Bit processors and Number_Of_Runs > 32000, */
178 /* overflow may occur for this array element. */
181 printf ("Dhrystone Benchmark, Version 2.1 (Language: C or C++)\n");
186 printf ("No run time input data\n\n");
190 printf ("With run time input data\n\n");
193 printf ("Compiler %s\n", compiler);
194 printf ("Optimisation %s\n", options);
196 printf ("Register option selected\n\n");
198 printf ("Register option not selected\n\n");
199 strcpy(Reg_Define, "Register option Not selected.");
205 printf ("Program compiled with 'register' attribute\n");
210 printf ("Program compiled without 'register' attribute\n");
214 printf ("Please give the number of runs through the benchmark: ");
221 printf ("Execution starts, %d runs through Dhrystone\n",
225 Number_Of_Runs = 5000;
230 Number_Of_Runs = Number_Of_Runs * 2;
232 Arr_2_Glob [8][7] = 10;
238 Begin_Time = dtime();
240 for (Run_Index = 1; Run_Index <= Number_Of_Runs; ++Run_Index)
245 /* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */
248 strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
250 Bool_Glob = ! Func_2 (Str_1_Loc, Str_2_Loc);
252 while (Int_1_Loc < Int_2_Loc) /* loop body executed once */
254 Int_3_Loc = 5 * Int_1_Loc - Int_2_Loc;
256 Proc_7 (Int_1_Loc, Int_2_Loc, &Int_3_Loc);
260 /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
261 Proc_8 (Arr_1_Glob, Arr_2_Glob, Int_1_Loc, Int_3_Loc);
264 for (Ch_Index = 'A'; Ch_Index <= Ch_2_Glob; ++Ch_Index)
265 /* loop body executed twice */
267 if (Enum_Loc == Func_1 (Ch_Index, 'C'))
268 /* then, not executed */
270 Proc_6 (Ident_1, &Enum_Loc);
271 strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 3'RD STRING");
272 Int_2_Loc = Run_Index;
273 Int_Glob = Run_Index;
276 /* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
277 Int_2_Loc = Int_2_Loc * Int_1_Loc;
278 Int_1_Loc = Int_2_Loc / Int_3_Loc;
279 Int_2_Loc = 7 * (Int_2_Loc - Int_3_Loc) - Int_1_Loc;
280 /* Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 */
284 } /* loop "for Run_Index" */
291 User_Time = End_Time - Begin_Time;
293 printf ("%12.0f runs %6.2f seconds \n",(double) Number_Of_Runs, User_Time);
302 Number_Of_Runs = Number_Of_Runs * 5;
305 } /* calibrate/run do while */
309 printf ("Final values (* implementation-dependent):\n");
311 printf ("Int_Glob: ");
312 if (Int_Glob == 5) printf ("O.K. ");
313 else printf ("WRONG ");
314 printf ("%d ", Int_Glob);
316 printf ("Bool_Glob: ");
317 if (Bool_Glob == 1) printf ("O.K. ");
318 else printf ("WRONG ");
319 printf ("%d\n", Bool_Glob);
321 printf ("Ch_1_Glob: ");
322 if (Ch_1_Glob == 'A') printf ("O.K. ");
323 else printf ("WRONG ");
324 printf ("%c ", Ch_1_Glob);
326 printf ("Ch_2_Glob: ");
327 if (Ch_2_Glob == 'B') printf ("O.K. ");
328 else printf ("WRONG ");
329 printf ("%c\n", Ch_2_Glob);
331 printf ("Arr_1_Glob[8]: ");
332 if (Arr_1_Glob[8] == 7) printf ("O.K. ");
333 else printf ("WRONG ");
334 printf ("%d ", Arr_1_Glob[8]);
336 printf ("Arr_2_Glob8/7: ");
337 if (Arr_2_Glob[8][7] == Number_Of_Runs + 10)
339 else printf ("WRONG ");
340 printf ("%10d\n", Arr_2_Glob[8][7]);
342 printf ("Ptr_Glob-> ");
343 printf (" Ptr_Comp: * %d\n", (int) Ptr_Glob->Ptr_Comp);
346 if (Ptr_Glob->Discr == 0) printf ("O.K. ");
347 else printf ("WRONG ");
348 printf ("%d ", Ptr_Glob->Discr);
350 printf ("Enum_Comp: ");
351 if (Ptr_Glob->variant.var_1.Enum_Comp == 2)
353 else printf ("WRONG ");
354 printf ("%d\n", Ptr_Glob->variant.var_1.Enum_Comp);
356 printf (" Int_Comp: ");
357 if (Ptr_Glob->variant.var_1.Int_Comp == 17) printf ("O.K. ");
358 else printf ("WRONG ");
359 printf ("%d ", Ptr_Glob->variant.var_1.Int_Comp);
361 printf ("Str_Comp: ");
362 if (strcmp(Ptr_Glob->variant.var_1.Str_Comp,
363 "DHRYSTONE PROGRAM, SOME STRING") == 0)
365 else printf ("WRONG ");
366 printf ("%s\n", Ptr_Glob->variant.var_1.Str_Comp);
368 printf ("Next_Ptr_Glob-> ");
369 printf (" Ptr_Comp: * %d", (int) Next_Ptr_Glob->Ptr_Comp);
370 printf (" same as above\n");
373 if (Next_Ptr_Glob->Discr == 0)
375 else printf ("WRONG ");
376 printf ("%d ", Next_Ptr_Glob->Discr);
378 printf ("Enum_Comp: ");
379 if (Next_Ptr_Glob->variant.var_1.Enum_Comp == 1)
381 else printf ("WRONG ");
382 printf ("%d\n", Next_Ptr_Glob->variant.var_1.Enum_Comp);
384 printf (" Int_Comp: ");
385 if (Next_Ptr_Glob->variant.var_1.Int_Comp == 18)
387 else printf ("WRONG ");
388 printf ("%d ", Next_Ptr_Glob->variant.var_1.Int_Comp);
390 printf ("Str_Comp: ");
391 if (strcmp(Next_Ptr_Glob->variant.var_1.Str_Comp,
392 "DHRYSTONE PROGRAM, SOME STRING") == 0)
394 else printf ("WRONG ");
395 printf ("%s\n", Next_Ptr_Glob->variant.var_1.Str_Comp);
397 printf ("Int_1_Loc: ");
400 else printf ("WRONG ");
401 printf ("%d ", Int_1_Loc);
403 printf ("Int_2_Loc: ");
406 else printf ("WRONG ");
407 printf ("%d\n", Int_2_Loc);
409 printf ("Int_3_Loc: ");
412 else printf ("WRONG ");
413 printf ("%d ", Int_3_Loc);
415 printf ("Enum_Loc: ");
418 else printf ("WRONG ");
419 printf ("%d\n", Enum_Loc);
421 printf ("Str_1_Loc: ");
422 if (strcmp(Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING") == 0)
424 else printf ("WRONG ");
425 printf ("%s\n", Str_1_Loc);
427 printf ("Str_2_Loc: ");
428 if (strcmp(Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING") == 0)
430 else printf ("WRONG ");
431 printf ("%s\n", Str_2_Loc);
436 if (User_Time < Too_Small_Time)
438 printf ("Measured time too small to obtain meaningful results\n");
439 printf ("Please increase number of runs\n");
444 Microseconds = User_Time * Mic_secs_Per_Second
445 / (double) Number_Of_Runs;
446 Dhrystones_Per_Second = (double) Number_Of_Runs / User_Time;
447 Vax_Mips = Dhrystones_Per_Second / 1757.0;
449 printf ("Microseconds for one run through Dhrystone: ");
450 printf ("%12.2lf \n", Microseconds);
451 printf ("Dhrystones per Second: ");
452 printf ("%10.0lf \n", Dhrystones_Per_Second);
453 printf ("VAX MIPS rating = ");
454 printf ("%12.2lf \n",Vax_Mips);
457 /************************************************************************
458 * Type details of hardware, software etc. *
459 ************************************************************************/
463 printf ("Enter the following which will be added with results to file DHRY.TXT\n");
464 printf ("When submitting a number of results you need only provide details once\n");
465 printf ("but a cross reference such as an abbreviated CPU type would be useful.\n");
466 printf ("You can kill (exit or close) the program now and no data will be added.\n\n");
468 printf ("PC Supplier/model ? ");
471 printf ("CPU chip ? ");
474 printf ("Clock MHz ? ");
477 printf ("Cache size ? ");
480 printf ("Chipset & H/W options ? ");
483 printf ("OS/DOS version ? ");
486 printf ("Your name ? ");
489 printf ("Company/Location ? ");
492 printf ("E-mail address ? ");
495 /************************************************************************
496 * Add results to output file Dhry.txt *
497 ************************************************************************/
498 fprintf (Ap, "-------------------- -----------------------------------"
500 fprintf (Ap, "Dhrystone Benchmark Version 2.1 (Language: C++)\n\n");
501 fprintf (Ap, "PC model %s\n", general[1]);
502 fprintf (Ap, "CPU %s\n", general[2]);
503 fprintf (Ap, "Clock MHz %s\n", general[3]);
504 fprintf (Ap, "Cache %s\n", general[4]);
505 fprintf (Ap, "Options %s\n", general[5]);
506 fprintf (Ap, "OS/DOS %s\n", general[6]);
507 fprintf (Ap, "Compiler %s\n", compiler);
508 fprintf (Ap, "OptLevel %s\n", options);
509 fprintf (Ap, "Run by %s\n", general[7]);
510 fprintf (Ap, "From %s\n", general[8]);
511 fprintf (Ap, "Mail %s\n\n", general[0]);
513 fprintf (Ap, "Final values (* implementation-dependent):\n");
515 fprintf (Ap, "Int_Glob: ");
516 if (Int_Glob == 5) fprintf (Ap, "O.K. ");
517 else fprintf (Ap, "WRONG ");
518 fprintf (Ap, "%d\n", Int_Glob);
520 fprintf (Ap, "Bool_Glob: ");
521 if (Bool_Glob == 1) fprintf (Ap, "O.K. ");
522 else fprintf (Ap, "WRONG ");
523 fprintf (Ap, "%d\n", Bool_Glob);
525 fprintf (Ap, "Ch_1_Glob: ");
526 if (Ch_1_Glob == 'A') fprintf (Ap, "O.K. ");
527 else fprintf (Ap, "WRONG ");
528 fprintf (Ap, "%c\n", Ch_1_Glob);
530 fprintf (Ap, "Ch_2_Glob: ");
531 if (Ch_2_Glob == 'B') fprintf (Ap, "O.K. ");
532 else fprintf (Ap, "WRONG ");
533 fprintf (Ap, "%c\n", Ch_2_Glob);
535 fprintf (Ap, "Arr_1_Glob[8]: ");
536 if (Arr_1_Glob[8] == 7) fprintf (Ap, "O.K. ");
537 else fprintf (Ap, "WRONG ");
538 fprintf (Ap, "%d\n", Arr_1_Glob[8]);
540 fprintf (Ap, "Arr_2_Glob8/7: ");
541 if (Arr_2_Glob[8][7] == Number_Of_Runs + 10)
542 fprintf (Ap, "O.K. ");
543 else fprintf (Ap, "WRONG ");
544 fprintf (Ap, "%10d\n", Arr_2_Glob[8][7]);
546 fprintf (Ap, "Ptr_Glob-> \n");
547 fprintf (Ap, " Ptr_Comp: * %d\n", (int) Ptr_Glob->Ptr_Comp);
549 fprintf (Ap, " Discr: ");
550 if (Ptr_Glob->Discr == 0) fprintf (Ap, "O.K. ");
551 else fprintf (Ap, "WRONG ");
552 fprintf (Ap, "%d\n", Ptr_Glob->Discr);
554 fprintf (Ap, " Enum_Comp: ");
555 if (Ptr_Glob->variant.var_1.Enum_Comp == 2)
556 fprintf (Ap, "O.K. ");
557 else fprintf (Ap, "WRONG ");
558 fprintf (Ap, "%d\n", Ptr_Glob->variant.var_1.Enum_Comp);
560 fprintf (Ap, " Int_Comp: ");
561 if (Ptr_Glob->variant.var_1.Int_Comp == 17) fprintf (Ap, "O.K. ");
562 else fprintf (Ap, "WRONG ");
563 fprintf (Ap, "%d\n", Ptr_Glob->variant.var_1.Int_Comp);
565 fprintf (Ap, " Str_Comp: ");
566 if (strcmp(Ptr_Glob->variant.var_1.Str_Comp,
567 "DHRYSTONE PROGRAM, SOME STRING") == 0)
568 fprintf (Ap, "O.K. ");
569 else fprintf (Ap, "WRONG ");
570 fprintf (Ap, "%s\n", Ptr_Glob->variant.var_1.Str_Comp);
572 fprintf (Ap, "Next_Ptr_Glob-> \n");
573 fprintf (Ap, " Ptr_Comp: * %d", (int) Next_Ptr_Glob->Ptr_Comp);
574 fprintf (Ap, " same as above\n");
576 fprintf (Ap, " Discr: ");
577 if (Next_Ptr_Glob->Discr == 0)
578 fprintf (Ap, "O.K. ");
579 else fprintf (Ap, "WRONG ");
580 fprintf (Ap, "%d\n", Next_Ptr_Glob->Discr);
582 fprintf (Ap, " Enum_Comp: ");
583 if (Next_Ptr_Glob->variant.var_1.Enum_Comp == 1)
584 fprintf (Ap, "O.K. ");
585 else fprintf (Ap, "WRONG ");
586 fprintf (Ap, "%d\n", Next_Ptr_Glob->variant.var_1.Enum_Comp);
588 fprintf (Ap, " Int_Comp: ");
589 if (Next_Ptr_Glob->variant.var_1.Int_Comp == 18)
590 fprintf (Ap, "O.K. ");
591 else fprintf (Ap, "WRONG ");
592 fprintf (Ap, "%d\n", Next_Ptr_Glob->variant.var_1.Int_Comp);
594 fprintf (Ap, " Str_Comp: ");
595 if (strcmp(Next_Ptr_Glob->variant.var_1.Str_Comp,
596 "DHRYSTONE PROGRAM, SOME STRING") == 0)
597 fprintf (Ap, "O.K. ");
598 else fprintf (Ap, "WRONG ");
599 fprintf (Ap, "%s\n", Next_Ptr_Glob->variant.var_1.Str_Comp);
601 fprintf (Ap, "Int_1_Loc: ");
603 fprintf (Ap, "O.K. ");
604 else fprintf (Ap, "WRONG ");
605 fprintf (Ap, "%d\n", Int_1_Loc);
607 fprintf (Ap, "Int_2_Loc: ");
609 fprintf (Ap, "O.K. ");
610 else fprintf (Ap, "WRONG ");
611 fprintf (Ap, "%d\n", Int_2_Loc);
613 fprintf (Ap, "Int_3_Loc: ");
615 fprintf (Ap, "O.K. ");
616 else fprintf (Ap, "WRONG ");
617 fprintf (Ap, "%d\n", Int_3_Loc);
619 fprintf (Ap, "Enum_Loc: ");
621 fprintf (Ap, "O.K. ");
622 else fprintf (Ap, "WRONG ");
623 fprintf (Ap, "%d\n", Enum_Loc);
625 fprintf (Ap, "Str_1_Loc: ");
626 if (strcmp(Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING") == 0)
627 fprintf (Ap, "O.K. ");
628 else fprintf (Ap, "WRONG ");
629 fprintf (Ap, "%s\n", Str_1_Loc);
631 fprintf (Ap, "Str_2_Loc: ");
632 if (strcmp(Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING") == 0)
633 fprintf (Ap, "O.K. ");
634 else fprintf (Ap, "WRONG ");
635 fprintf (Ap, "%s\n", Str_2_Loc);
639 fprintf(Ap,"%s\n",Reg_Define);
641 fprintf(Ap,"Microseconds 1 loop: %12.2lf\n",Microseconds);
642 fprintf(Ap,"Dhrystones / second: %10.0lf\n",Dhrystones_Per_Second);
643 fprintf(Ap,"VAX MIPS rating: %12.2lf\n\n",Vax_Mips);
648 printf ("A new results file will have been created in the same directory as the\n");
649 printf (".EXE files if one did not already exist. If you made a mistake on input, \n");
650 printf ("you can use a text editor to correct it, delete the results or copy \n");
651 printf ("them to a different file name. If you intend to run multiple tests you\n");
652 printf ("you may wish to rename DHRY.TXT with a more informative title.\n\n");
653 printf ("Please submit feedback and results files as a posting in Section 12\n");
654 printf ("or to Roy_Longbottom@compuserve.com\n\n");
658 printf("Press any key to exit\n");
659 printf ("\nIf this is displayed you must close the window in the normal way\n");
664 void Proc_1 (REG Rec_Pointer Ptr_Val_Par)
669 REG Rec_Pointer Next_Record = Ptr_Val_Par->Ptr_Comp;
670 /* == Ptr_Glob_Next */
671 /* Local variable, initialized with Ptr_Val_Par->Ptr_Comp, */
672 /* corresponds to "rename" in Ada, "with" in Pascal */
674 structassign (*Ptr_Val_Par->Ptr_Comp, *Ptr_Glob);
675 Ptr_Val_Par->variant.var_1.Int_Comp = 5;
676 Next_Record->variant.var_1.Int_Comp
677 = Ptr_Val_Par->variant.var_1.Int_Comp;
678 Next_Record->Ptr_Comp = Ptr_Val_Par->Ptr_Comp;
679 Proc_3 (&Next_Record->Ptr_Comp);
680 /* Ptr_Val_Par->Ptr_Comp->Ptr_Comp
681 == Ptr_Glob->Ptr_Comp */
682 if (Next_Record->Discr == Ident_1)
685 Next_Record->variant.var_1.Int_Comp = 6;
686 Proc_6 (Ptr_Val_Par->variant.var_1.Enum_Comp,
687 &Next_Record->variant.var_1.Enum_Comp);
688 Next_Record->Ptr_Comp = Ptr_Glob->Ptr_Comp;
689 Proc_7 (Next_Record->variant.var_1.Int_Comp, 10,
690 &Next_Record->variant.var_1.Int_Comp);
692 else /* not executed */
693 structassign (*Ptr_Val_Par, *Ptr_Val_Par->Ptr_Comp);
697 void Proc_2 (One_Fifty *Int_Par_Ref)
700 /* *Int_Par_Ref == 1, becomes 4 */
704 Enumeration Enum_Loc;
706 Int_Loc = *Int_Par_Ref + 10;
707 do /* executed once */
708 if (Ch_1_Glob == 'A')
712 *Int_Par_Ref = Int_Loc - Int_Glob;
715 while (Enum_Loc != Ident_1); /* true */
719 void Proc_3 (Rec_Pointer *Ptr_Ref_Par)
722 /* Ptr_Ref_Par becomes Ptr_Glob */
725 if (Ptr_Glob != Null)
727 *Ptr_Ref_Par = Ptr_Glob->Ptr_Comp;
728 Proc_7 (10, Int_Glob, &Ptr_Glob->variant.var_1.Int_Comp);
732 void Proc_4 () /* without parameters */
738 Bool_Loc = Ch_1_Glob == 'A';
739 Bool_Glob = Bool_Loc | Bool_Glob;
744 void Proc_5 () /* without parameters */
753 /* Procedure for the assignment of structures, */
754 /* if the C compiler doesn't support this feature */
755 #ifdef NOSTRUCTASSIGN
761 while (l--) *d++ = *s++;
769 /* #include <ctype.h> */
771 #define HZ CLOCKS_PER_SEC
776 q = (double)tnow / (double)HZ;