home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / xc212os2.zip / SAMPLES / SIMPLE / dry.c < prev    next >
C/C++ Source or Header  |  1995-07-25  |  9KB  |  313 lines

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <time.h>
  4.  
  5. #define REG register
  6.  
  7. #define structassign(d,s) d=s
  8.  
  9. typedef enum
  10. {
  11.         Ident1, Ident2, Ident3, Ident4, Ident5
  12. } Enumeration;
  13. typedef int     OneToThirty;
  14. typedef int     OneToFifty;
  15. typedef char    CapitalLetter;
  16. typedef char    String30[31];
  17. typedef int     Array1Dim[51];
  18. typedef int     Array2Dim[51][51];
  19.  
  20. struct Record
  21. {
  22.         struct Record  *PtrComp;
  23.                         Enumeration Discr;
  24.                         Enumeration EnumComp;
  25.                         OneToFifty IntComp;
  26.                         String30 StringComp;
  27. };
  28.  
  29. typedef struct Record   RecordType;
  30. typedef struct Record  *RecordPtr;
  31. typedef int     boolean;
  32.  
  33. #define NULL 0
  34. #define TRUE 1
  35. #define FALSE 0
  36. #ifndef REG
  37. #define REG
  38. #endif
  39.  
  40. void Proc8 (Array1Dim a0, Array2Dim a1, OneToFifty o0, OneToFifty o1);
  41. void Proc7 (OneToFifty o0, OneToFifty o1, OneToFifty *o2);
  42. void Proc6 (Enumeration e0, Enumeration *e1 );
  43. void Proc5 (void);
  44. void Proc4 (void);
  45. void Proc3 (RecordPtr *r);
  46. void Proc2 (OneToFifty *o0);
  47. void Proc1 (RecordPtr r);
  48. void Proc0 (void);
  49.  
  50. Enumeration Func1 ( CapitalLetter l0, CapitalLetter l1 );
  51. boolean Func2 ( String30 s0, String30 s1 );
  52.  
  53. main ()
  54. {
  55.         Proc0 ();
  56. }
  57.  
  58. int     IntGlob;
  59. boolean BoolGlob;
  60. char    Char1Glob;
  61. char    Char2Glob;
  62. Array1Dim Array1Glob;
  63. Array2Dim Array2Glob;
  64. RecordPtr PtrGlob;
  65. RecordPtr PtrGlobNext;
  66.  
  67. void Proc0 ()
  68. {
  69.         OneToFifty IntLoc1;
  70.         REG OneToFifty IntLoc2;
  71.         OneToFifty IntLoc3;
  72.         REG char        CharLoc;
  73.         REG char        CharIndex;
  74.             Enumeration EnumLoc;
  75.         String30 String1Loc;
  76.         String30 String2Loc;
  77.  
  78. #define LOOPS 4000000
  79.         long    starttime;
  80.         long    benchtime;
  81.         long    nulltime;
  82.         long    i;
  83.  
  84.         printf ("Please, wait about 60 seconds\n");
  85.  
  86.         starttime = time (0L);
  87.         for (i = 0; i < LOOPS; ++i);
  88.         nulltime = time (0L) - starttime;
  89.  
  90.         PtrGlobNext = (RecordPtr) malloc (sizeof (RecordType));
  91.         PtrGlob = (RecordPtr) malloc (sizeof (RecordType));
  92.         PtrGlob -> PtrComp = PtrGlobNext;
  93.         PtrGlob -> Discr = Ident1;
  94.         PtrGlob -> EnumComp = Ident3;
  95.         PtrGlob -> IntComp = 40;
  96.         strcpy (PtrGlob -> StringComp, "DHRYSTONE PROGRAM, SOME STRING");
  97.     strcpy (String1Loc, "DHRYSTONE PROGRAM, 1'ST STRING");
  98.  
  99.         starttime = time (0L);
  100.         for (i = 0; i < LOOPS; ++i)
  101.         {
  102.                 Proc5 ();
  103.                 Proc4 ();
  104.                 IntLoc1 = 2;
  105.                 IntLoc2 = 3;
  106.                 strcpy (String2Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
  107.                 EnumLoc = Ident2;
  108.                 BoolGlob =! Func2 (String1Loc, String2Loc);
  109.                 while (IntLoc1 < IntLoc2)
  110.                 {
  111.                         IntLoc3 = 5 * IntLoc1 - IntLoc2;
  112.                         Proc7 (IntLoc1, IntLoc2, &IntLoc3);
  113.                         ++IntLoc1;
  114.                 }
  115.                 Proc8 (Array1Glob, Array2Glob, IntLoc1, IntLoc3);
  116.                 Proc1 (PtrGlob);
  117.                 for (CharIndex = 'A'; CharIndex <= Char2Glob; ++CharIndex)
  118.                         if (EnumLoc == Func1 (CharIndex, 'C'))
  119.                                 Proc6 (Ident1, &EnumLoc);
  120.                 IntLoc3 = IntLoc2 * IntLoc1;
  121.                 IntLoc2 = IntLoc3 / IntLoc1;
  122.                 IntLoc2 = 7 * (IntLoc3 - IntLoc2) - IntLoc1;
  123.                 Proc2 (&IntLoc1);
  124.         }
  125.         benchtime = time (0L) - starttime - nulltime;
  126.         printf ("Dhrystone time for %ld passes = %ld\n", (long) LOOPS, benchtime);
  127.         printf ("This machine benchmarks at %ld dhrystones/second\n",
  128.                         ((long) LOOPS) / benchtime);
  129. }
  130.  
  131. void Proc1 (PtrParIn)
  132. REG RecordPtr PtrParIn;
  133. {
  134. #define NextRecord (*(PtrParIn->PtrComp))
  135.         structassign (NextRecord, *PtrGlob);
  136.         PtrParIn -> IntComp = 5;
  137.         NextRecord.IntComp = PtrParIn -> IntComp;
  138.         NextRecord.PtrComp = PtrParIn -> PtrComp;
  139.         Proc3 (&NextRecord.PtrComp);
  140.         if (NextRecord.Discr == Ident1)
  141.         {
  142.                 NextRecord.IntComp = 6;
  143.                 Proc6 (PtrParIn -> EnumComp, &NextRecord.EnumComp);
  144.                 NextRecord.PtrComp = PtrGlob -> PtrComp;
  145.                 Proc7 (NextRecord.IntComp, 10, &NextRecord.IntComp);
  146.         }
  147.         else
  148.                 structassign (*PtrParIn, NextRecord);
  149. #undef NextRecord
  150. }
  151.  
  152. void Proc2 (IntParIO)
  153. OneToFifty * IntParIO;
  154. {
  155.         REG OneToFifty IntLoc;
  156.         REG Enumeration EnumLoc;
  157.  
  158.         IntLoc = *IntParIO + 10;
  159.         for (;;)
  160.         {
  161.                 if (Char1Glob == 'A')
  162.                 {
  163.                         --IntLoc;
  164.                         *IntParIO = IntLoc - IntGlob;
  165.                         EnumLoc = Ident1;
  166.                 }
  167.                 if (EnumLoc == Ident1)
  168.                         break;
  169.         }
  170. }
  171.  
  172. void Proc3 (PtrParOut)
  173. RecordPtr * PtrParOut;
  174. {
  175.         if (PtrGlob != NULL)
  176.                 *PtrParOut = PtrGlob -> PtrComp;
  177.         else
  178.                 IntGlob = 100;
  179.         Proc7 (10, IntGlob, &PtrGlob -> IntComp);
  180. }
  181.  
  182. void Proc4 ()
  183. {
  184.         REG boolean BoolLoc;
  185.  
  186.         BoolLoc = Char1Glob == 'A';
  187.         BoolLoc |= BoolGlob;
  188.         Char2Glob = 'B';
  189. }
  190.  
  191. void Proc5 ()
  192. {
  193.         Char1Glob = 'A';
  194.         BoolGlob = FALSE;
  195. }
  196.  
  197. boolean Func3 (Enumeration e0);
  198.  
  199. void Proc6 (EnumParIn, EnumParOut)
  200. REG Enumeration EnumParIn;
  201. REG Enumeration * EnumParOut;
  202. {
  203.         *EnumParOut = EnumParIn;
  204.         if (!Func3 (EnumParIn))
  205.                 *EnumParOut = Ident4;
  206.         switch (EnumParIn)
  207.         {
  208.                 case Ident1:
  209.                         *EnumParOut = Ident1;
  210.                         break;
  211.                 case Ident2:
  212.                         if (IntGlob > 100)
  213.                                 *EnumParOut = Ident1;
  214.                         else
  215.                                 *EnumParOut = Ident4;
  216.                         break;
  217.                 case Ident3:
  218.                         *EnumParOut = Ident2;
  219.                         break;
  220.                 case Ident4:
  221.                         break;
  222.                 case Ident5:
  223.                         *EnumParOut = Ident3;
  224.         }
  225. }
  226.  
  227. void Proc7 (IntParI1, IntParI2, IntParOut)
  228. OneToFifty IntParI1;
  229. OneToFifty IntParI2;
  230. OneToFifty *IntParOut;
  231. {
  232.         REG OneToFifty IntLoc;
  233.  
  234.         IntLoc = IntParI1 + 2;
  235.         *IntParOut = IntParI2 + IntLoc;
  236. }
  237.  
  238. void Proc8 (Array1Par, Array2Par, IntParI1, IntParI2)
  239. Array1Dim Array1Par;
  240. Array2Dim Array2Par;
  241. OneToFifty IntParI1;
  242. OneToFifty IntParI2;
  243. {
  244.         REG OneToFifty IntLoc;
  245.         REG OneToFifty IntIndex;
  246.  
  247.         IntLoc = IntParI1 + 5;
  248.         Array1Par[IntLoc] = IntParI2;
  249.         Array1Par[IntLoc + 1] = Array1Par[IntLoc];
  250.         Array1Par[IntLoc + 30] = IntLoc;
  251.         for (IntIndex = IntLoc; IntIndex <= (IntLoc + 1); ++IntIndex)
  252.                 ++Array2Par[IntLoc][IntLoc - 1];
  253.         Array2Par[IntLoc + 20][IntLoc] = Array1Par[IntLoc];
  254.         IntGlob = 5;
  255. }
  256.  
  257. Enumeration Func1 (CharPar1, CharPar2)
  258. CapitalLetter CharPar1;
  259. CapitalLetter CharPar2;
  260. {
  261.         REG CapitalLetter CharLoc1;
  262.         REG CapitalLetter CharLoc2;
  263.  
  264.         CharLoc1 = CharPar1;
  265.         CharLoc2 = CharLoc1;
  266.         if (CharLoc2 != CharPar2)
  267.                 return (Ident1);
  268.         else
  269.                 return (Ident2);
  270. }
  271.  
  272. boolean Func2 (StrParI1, StrParI2)
  273. String30 StrParI1;
  274. String30 StrParI2;
  275. {
  276.         REG OneToThirty IntLoc;
  277.         REG CapitalLetter CharLoc;
  278.  
  279.         IntLoc = 1;
  280.         while (IntLoc <= 1)
  281.                 if (Func1 (StrParI1[IntLoc], StrParI2[IntLoc + 1]) == Ident1)
  282.                 {
  283.                         CharLoc = 'A';
  284.                         ++IntLoc;
  285.                 }
  286.         if (CharLoc >= 'W' && CharLoc <= 'Z')
  287.                 IntLoc = 7;
  288.         if (CharLoc == 'X')
  289.                 return (TRUE);
  290.         else
  291.         {
  292.                 if (strcmp (StrParI1, StrParI2) > 0)
  293.                 {
  294.                         IntLoc += 7;
  295.                         return (TRUE);
  296.                 }
  297.                 else
  298.                         return (FALSE);
  299.         }
  300. }
  301.  
  302. boolean Func3 (EnumParIn)
  303. REG Enumeration EnumParIn;
  304. {
  305.         REG Enumeration EnumLoc;
  306.  
  307.         EnumLoc = EnumParIn;
  308.         if (EnumLoc == Ident3)
  309.                 return (TRUE);
  310.         return (FALSE);
  311. }
  312.  
  313.