home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / BENCHMARKS / dhrystone.c < prev    next >
C/C++ Source or Header  |  2009-11-06  |  11KB  |  416 lines

  1.  /*
  2.  *    "DHRYSTONE" Benchmark Program
  3.  *
  4.  *    The following program contains statments of a high-level
  5.  *    programming language (C) in a distribution considered
  6.  *    representative:
  7.  *
  8.  *    assignments                53%
  9.  *    control statements         32%
  10.  *    procedure, function calls  15%
  11.  *    100 statments are dynamically executed. The program is
  12.  *    balanced with respect to the three aspects:
  13.  *             - statements type
  14.  *             - operand type (for simple data types)
  15.  *             - operand access
  16.  *                 operand global, local, parameter, or constant.
  17.  *
  18.  *     The combination of these three aspects is balanced only
  19.  *     approximately.
  20.  *
  21.  *     The program does not compute anything meaningful, but it
  22.  *     is syntactically and semantically correct.
  23.  *
  24.  *
  25.  */
  26.  
  27. #include <stdio.h>
  28. #include <setsys.h>
  29.  
  30. /* Accuracy of timings controlled by next two lines */
  31. /*#define LOOPS   50000 */  /*Use this for slow or 16 bit machines */
  32. #define LOOPS 500000  /*Use the for faster machines */
  33.  
  34. /* Compiler dependent options */
  35. #define ENUM            /*Define if compiler has enum's */
  36. #define STRUCTASSIGN  1    /*Define if compiler can assign structures*/
  37. #define REG register
  38. /* define only one of the next two defines */
  39. #define TIME                /*Use time(2) time function*/
  40. /*#define TIMES                   /* Use times(2) time function */
  41. #include <time.h>
  42.  
  43. /* define the granularity of your times(2) function (when used) */
  44. /*#define HZ      50   /* times(2) returns 1/50 second (europe?)*/
  45. #ifndef  ATT3B
  46. #define   HZ      60   /* times (2) returns 1/60 second (most) */
  47. #else
  48. #define   HZ      100  /* times (2) returns 1/1000 second (WECo)*/
  49. #endif
  50.  
  51. char Version[] = "1.1";
  52.  
  53. #ifndef STRUCTASSIGN
  54. #define structassign(d, s)   memcpy(&(d), &(s), sizeof(d))
  55. #else
  56. #define structassign(d, s)   d = s
  57. #endif
  58.  
  59. #ifdef ENUM
  60. typedef enum
  61.         {Ident1, Ident2, Ident3, Ident4, Ident5} Enumeration;
  62. #else
  63. #define Ident1  1
  64. #define Ident2  2
  65. #define Ident3  3
  66. #define Ident4  4
  67. #define Ident5  5
  68. #define Enumeration int
  69. #endif
  70.  
  71. #define OneToThirty int
  72. #define OneToFifty int
  73. #define CapitalLetter char
  74.  
  75. struct Record
  76. {
  77.     struct Record      *PtrComp;
  78.     Enumeration        Discr;
  79.     Enumeration        EnumComp;
  80.     OneToFifty         IntComp;
  81.     char               StringComp[30];
  82. };
  83.  
  84. #define RecordType     struct Record
  85. #define RecordPtr      RecordType *
  86. #define boolean        int
  87.  
  88. /* #define NULL           0 */
  89. #define TRUE           1
  90. #define FALSE          0
  91.  
  92. #ifndef REG
  93. #define REG
  94. #endif
  95.  
  96. extern Enumeration      Func1();
  97. extern boolean          Func2();
  98.  
  99. #ifdef  TIMES
  100. #include <types.h>
  101. #include <time.h>
  102. #endif
  103.  
  104. double seconds ;
  105.  
  106. main()
  107. {
  108.         Proc0();
  109.         exit(0);
  110. }
  111.  
  112. /*
  113.  * Package 1
  114.  */
  115. int        IntGlob;
  116. boolean    BoolGlob;
  117. char       Char1Glob;
  118. char       Char2Glob;
  119. int        Array1Glob[51];
  120. int        Array2Glob[51][51];
  121. RecordPtr  PtrGlb;
  122. RecordPtr  PtrGlbNext;
  123.  
  124. Proc0()
  125. {
  126.    OneToFifty            IntLoc1;
  127.    REG OneToFifty        IntLoc2;
  128.    OneToFifty            IntLoc3;
  129.    REG char              CharLoc;
  130.    REG char              CharIndex;
  131.    Enumeration           EnumLoc;
  132.    char                  String1Loc[30];
  133.    char                  String2Loc[30];
  134.    extern char           *malloc();
  135.    register unsigned int i ;
  136.  
  137. #ifdef TIME
  138.     time_t                 time();
  139.     time_t                 starttime;
  140.     time_t                 benchtime;
  141.     time_t                 nulltime;
  142.  
  143.     starttime = clock();
  144.     for (i =0; i < LOOPS; ++i);
  145.     /* Computes overhead of looping */
  146.     nulltime = clock();
  147.     nulltime = nulltime - starttime;
  148. #endif
  149. #ifdef TIMES
  150.       time_t              starttime;
  151.       time_t              benchtime;
  152.       time_t              nulltime;
  153.       struct tms          tms;
  154.  
  155.       times(&tms); starttime = tms.tms_utime;
  156.       for (i = 0; i < LOOPS; ++i);
  157.       times (&tms);
  158.       /* Computes overhead of looping */
  159.       nulltime = tms.tms_utime - starttime;
  160. #endif
  161.  
  162.       PtrGlbNext = (RecordPtr) malloc(sizeof(RecordType));
  163.       PtrGlb = (RecordPtr) malloc(sizeof(RecordType));
  164.       PtrGlb->PtrComp = PtrGlbNext;
  165.       PtrGlb->Discr = Ident1;
  166.       PtrGlb->EnumComp = Ident3;
  167.       PtrGlb->IntComp = 40;
  168.       strcpy(PtrGlb->StringComp, "DHRYSTONE PROGRAM, SOME STRING");
  169.       strcpy(String1Loc, "DHRYSTONE PROGRAMM 1'ST STRING");
  170.       Array2Glob[8][7] = 10;
  171.  
  172. /****************
  173. - Start Timer -
  174. ****************/
  175. #ifdef TIME
  176.         starttime = clock();
  177. #endif
  178. #ifdef TIMES
  179.        times(&tms); starttime = tms.tms_utime;
  180. #endif
  181.        for (i = 0; i < LOOPS; ++i)
  182.        {
  183.           Proc5();
  184.           Proc4();
  185.           IntLoc1 = 2;
  186.           IntLoc2 = 3;
  187.           strcpy(String2Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
  188.           EnumLoc = Ident2;
  189.           BoolGlob = ! Func2(String1Loc, String2Loc);
  190.           while ( IntLoc1 < IntLoc2)
  191.           {
  192.             IntLoc3 = 5 * IntLoc1 - IntLoc2;
  193.             Proc7(IntLoc1, IntLoc2, &IntLoc3);
  194.             ++IntLoc1;
  195.           }
  196.           Proc8(Array1Glob, Array2Glob, IntLoc1, IntLoc3);
  197.           Proc1(PtrGlb);
  198.           for (CharIndex = 'A' ; CharIndex <= Char2Glob;
  199.                 ++CharIndex)
  200.                if ( EnumLoc == Func1(CharIndex, 'C'))
  201.                         Proc6(Ident1, &EnumLoc);
  202.           IntLoc3 = IntLoc2 * IntLoc1;
  203.           IntLoc2 = IntLoc3 / IntLoc1;
  204.           IntLoc2 = 7 * ( IntLoc3 - IntLoc2) - IntLoc1;
  205.           Proc2 ( &IntLoc1 );
  206.      }
  207. /***************
  208. - Stop Timer -
  209. ***************/
  210.  
  211. #ifdef TIME
  212.           benchtime = clock();
  213.           benchtime -= starttime;
  214.           benchtime -= nulltime;
  215.           seconds = (double)benchtime / (double)CLK_TCK;
  216.           printf ("Dhrystone(%s) time form %ld passes = %.2f\n",
  217.                   Version, (long) LOOPS, seconds);
  218.           printf("This machine bnechmarks at %.2f dhrystones/second\n",
  219.                  (double)((long) LOOPS) / seconds);
  220. #endif
  221. #ifdef TIMES
  222.           times(&tms);
  223.           benchtime = tms.tms_utime - starttime - nulltime;
  224.           printf("Dhrystone(%s) time for %ld passes = %ld\n",
  225.                 Vsersion, (long) LOOPS, benchtime/HZ);
  226.           printf("This machine benchmarks at %ld dhrystones/second\n",
  227.                 ((long LOOPS) * HZ / benchtime);
  228. #endif
  229. }
  230.  
  231. Proc1(PtrParIn)
  232. REG RecordPtr PtrParIn;
  233. {
  234. #define NextRecord     (*(PtrParIn->PtrComp))
  235.  
  236.           structassign(NextRecord, *PtrGlb);
  237.           PtrParIn->IntComp = 5;
  238.           NextRecord.IntComp = PtrParIn->IntComp;
  239.           NextRecord.PtrComp = PtrParIn->PtrComp;
  240.           Proc3(NextRecord.PtrComp);
  241.           if (NextRecord.Discr == Ident1 )
  242.           {
  243.               NextRecord.IntComp = 6;
  244.               Proc6(PtrParIn->EnumComp, &NextRecord.EnumComp);
  245.               NextRecord.PtrComp = PtrGlb->PtrComp;
  246.               Proc7(NextRecord.IntComp, 10, &NextRecord.IntComp);
  247.            }
  248.            else
  249.               structassign(*PtrParIn, NextRecord);
  250. #undef NextRecord
  251. }
  252.  
  253. Proc2(IntParIO)
  254. OneToFifty    *IntParIO;
  255. {
  256.          REG OneToFifty    IntLoc;
  257.          REG Enumeration   EnumLoc;
  258.  
  259.          IntLoc = *IntParIO + 10;
  260.          for (;;)
  261.          {
  262.               if (Char1Glob == 'A')
  263.                 {
  264.                  --IntLoc;
  265.                  *IntParIO = IntLoc - IntGlob;
  266.                  EnumLoc = Ident1;
  267.                  }
  268.           if (EnumLoc == Ident1)
  269.               break;
  270.         }
  271.  }
  272.  
  273. Proc3 (PtrParOut)
  274. RecordPtr          *PtrParOut;
  275. {
  276.          if  (PtrGlb != NULL)
  277.               *PtrParOut = PtrGlb->PtrComp;
  278.           else
  279.               IntGlob = 100;
  280.           Proc7(10, IntGlob, &PtrGlb->IntComp);
  281. }
  282.  
  283. Proc4()
  284. {
  285.          REG boolean       BoolLoc;
  286.  
  287.          BoolLoc = Char1Glob == 'A';
  288.          BoolLoc |= BoolGlob;
  289.          Char2Glob = 'B';
  290. }
  291.  
  292. Proc5()
  293. {
  294.          Char1Glob ='A';
  295.          BoolGlob = FALSE;
  296. }
  297.  
  298. extern boolean Func3();
  299.  
  300. Proc6 (EnumParIn, EnumParOut)
  301. REG Enumeration EnumParIn;
  302. REG Enumeration *EnumParOut;
  303. {
  304.          *EnumParOut = EnumParIn;
  305.          if (! Func3(EnumParIn) )
  306.              *EnumParOut = Ident4;
  307.           switch (EnumParIn)
  308.           {
  309.            case Ident1: *EnumParOut = Ident1; break;
  310.            case Ident2: if ( IntGlob > 100)
  311.                              *EnumParOut = Ident1;
  312.                          else
  313.                              *EnumParOut = Ident4;
  314.                          break;
  315.             case Ident3: *EnumParOut = Ident2; break;
  316.             case Ident4: break;
  317.             case Ident5: *EnumParOut = Ident3;
  318.            }
  319. }
  320.  
  321. Proc7(IntParI1, IntParI2, IntParOut)
  322. OneToFifty      IntParI1;
  323. OneToFifty      IntParI2;
  324. OneToFifty      *IntParOut;
  325. {
  326.          REG OneToFifty  IntLoc;
  327.  
  328.          IntLoc = IntParI1 + 2;
  329.          *IntParOut = IntParI2 + IntLoc;
  330. }
  331.  
  332. Proc8 (Array1Par, Array2Par, IntParI1, IntParI2)
  333. int               Array1Par[51];
  334. int               Array2Par[51][51];
  335. OneToFifty        IntParI1;
  336. OneToFifty        IntParI2;
  337. {
  338.          REG OneToFifty IntLoc;
  339.          REG OneToFifty IntIndex;
  340.  
  341.          IntLoc = IntParI1 + 5;
  342.          Array1Par[IntLoc] = IntParI2;
  343.          Array1Par[IntLoc+1] = Array1Par[IntLoc];
  344.          Array1Par[IntLoc+30] = IntLoc;
  345.          for ( IntIndex = IntLoc; IntIndex <= (IntLoc+1); ++IntIndex)
  346.              Array2Par[IntLoc][IntIndex] = IntLoc;
  347.          ++Array2Par[IntLoc][IntLoc-1];
  348.          Array2Par[IntLoc+20][IntLoc] = Array1Par[IntLoc];
  349.          IntGlob = 5;
  350. }
  351.  
  352. Enumeration Func1(CharPar1, CharPar2)
  353. CapitalLetter  CharPar1;
  354. CapitalLetter  CharPar2;
  355. {
  356.          REG CapitalLetter    CharLoc1;
  357.          REG CapitalLetter    CharLoc2;
  358.  
  359.          CharLoc1 = CharPar1;
  360.          CharLoc2 = CharLoc1;
  361.          if ( CharLoc2 != CharPar2)
  362.               return (Ident1);
  363.          else
  364.               return (Ident2);
  365. }
  366.  
  367. boolean Func2 (StrParI1, StrParI2)
  368. char   StrParI1[30];
  369. char   StrParI2[30];
  370. {
  371.          REG OneToThirty       IntLoc;
  372.          REG CapitalLetter     CharLoc;
  373.  
  374.          IntLoc = 1;
  375.          while (IntLoc <= 1)
  376.               if ( Func1 (StrParI1[IntLoc], StrParI2[IntLoc+1]) == Ident1)
  377.               {
  378.                    CharLoc = 'A';
  379.                    ++IntLoc;
  380.                }
  381.           if (CharLoc >= 'W' && CharLoc <= 'Z')
  382.               IntLoc = 7;
  383.           if (CharLoc == 'X')
  384.               return(TRUE);
  385.           else
  386.            {
  387.               if (strcmp (StrParI1, StrParI2) > 0)
  388.               {
  389.                    IntLoc += 7;
  390.                    return (TRUE);
  391.               }
  392.               else
  393.                    return (FALSE);
  394.             }
  395. }
  396.  
  397. boolean Func3(EnumParIn)
  398. REG Enumeration EnumParIn;
  399. {
  400.          REG Enumeration EnumLoc;
  401.  
  402.          EnumLoc = EnumParIn;
  403.          if (EnumLoc == Ident3) return (TRUE);
  404.          return (FALSE);
  405. }
  406.  
  407. #ifndef STRUCTASSIGN
  408. memcpy (d, s, l)
  409. register char   *d;
  410. register char   *s;
  411. register int    l;
  412. {
  413.         while (l--) *d++ = *s++;
  414. }
  415. #endif
  416.