home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast.iso / info / dhamp.c < prev    next >
Internet Message Format  |  1994-03-04  |  6KB

  1. Date:    Wed, 02 Mar 88 17:30:28 CST
  2. From:    David Camp <C04661DC@WUVMD>
  3. Subject: Re: Dhrystones, anyone?
  4. To:      "I've got 50nS memory. What did you say?" <kruger@16bits.dec.COM>
  5.  
  6. >I am interested in the Dhrystone, Whetstone, and other popular benchmarks.
  7. >Please mail to me. If you want the collection, I will collect them and
  8. >forward.
  9.  
  10. I typed this in from a magazine.  I think it was "Computer Language",
  11. but I am not certain.  I would appreciate your forwarding the collection.
  12. -David-
  13.  
  14. *----------------------------------------------------------------------*
  15. | (314) 362-3635                  Mr. David J. Camp                    |
  16. |                          ^      Division of Biostatistics, Box 8067  |
  17. | Room 1108D             < * >    Washington University Medical School |
  18. | 706 South Euclid         v      660 South Euclid                     |
  19. |                                 Saint Louis, MO 63110                |
  20. | Bitnet: C04661DC@WUVMD.BITNET                                        |
  21. | Internet: C04661DC%WUVMD.BITNET@CUNYVM.CUNY.EDU                      |
  22. *----------------------------------------------------------------------*
  23.  
  24. --------------------- FILE dhamp     c          ---------------------
  25. --------------------------- cut here --------------------------------
  26. /*      The dhampstone benchmark.  Written by Jack purdum. */
  27. /*      version 1.0, August 1,1985                         */
  28.  
  29. #include "stdio.h"
  30.  
  31. #define BELL 7          /* ASCII BELL code */
  32. #define FIB 24
  33. #define TINY 100
  34. #define MAXINT 179
  35. #define LITTLE 1000
  36. #define SMALL 9000
  37. #define PRECISION .000001
  38. #define FILENAME "zyxw.vut"
  39. #define NUMTEST 6
  40.  
  41. #ifndef ERR
  42.     #define ERR -1
  43. #endif
  44.  
  45. struct
  46.     {
  47.     int cresult;
  48.     int iresult;
  49.     int cprsult;
  50.     unsigned uresult;
  51.     long lresult;
  52.     double dresult;
  53.     } results;
  54.  
  55. main()
  56. {
  57. char buf1[TINY], buf2[TINY];
  58. int i = 0;
  59. unsigned fib ();
  60. long square, sq ();
  61. double dmath, sroot (), dply ();
  62.  
  63. printf("Start...%c\n\n",BELL);
  64. while (i < NUMTEST)
  65.     {
  66.     switch (i)
  67.         {
  68.     case (0):                                   /* Character test       */
  69.         results.cresult = stest (buf1,buf2);
  70.         printf ("\ncresult = %d\n",results.cresult);
  71.         break;
  72.     case (1):                                   /* Integer test         */
  73.         results.iresult = intest ();
  74.         printf ("\niresult = %d\n",results.iresult);
  75.         break;
  76.     case (2):                                   /* Unsigned test        */
  77.         results.uresult = fib (FIB);
  78.         printf ("\nuresult = %u\n",results.uresult);
  79.         break;
  80.     case (3):                                   /* Long test            */
  81.         square = 0L;
  82.         results.lresult = sq (square);
  83.         square = sq (results.lresult);          /* Check the value      */
  84.         printf ("\nlresult = %ld",results.lresult);
  85.         printf ("\n square = %ld\n",square);
  86.         break;
  87.     case (4):                                   /* Double test          */
  88.         results.dresult = sroot ((double) results.lresult);
  89.         printf ("\ndresult = %f\n",results.dresult);
  90.         dmath = dply (results.dresult);
  91.         printf ("  dmath = %f\n",dmath);
  92.         break;
  93.     case (5):                                   /* Disk copy            */
  94.         results.cprsult = mcopy ();
  95.         printf ("\b   copy = %d",results.cprsult);
  96.         break;
  97.     default:
  98.         break;
  99.         }
  100.     ++i;
  101.     }                                           /* End while i          */
  102. printf ("\n\n...End%c",BELL);
  103. }
  104.  
  105. long sq (big)           /* Function to square a number by iteration */
  106. long big;
  107. {
  108. int i;
  109. static long j = 1L;
  110.  
  111. if (!big)
  112.     for (i = 0; i < SMALL; ++i)
  113.         {
  114.         big += j;
  115.         j += 2;
  116.         }
  117. else
  118.     for (i = 0; i < SMALL; ++i)
  119.         {
  120.         j -= 2;
  121.         big -= j;
  122.         }
  123. return (big);
  124. }
  125.  
  126. double sroot (num)      /* Find square root of number */
  127. double num;
  128. {
  129. double temp1, temp2, abs ();
  130.  
  131. temp2 = num / 2.0;
  132. temp1 = num;
  133. while (temp1 > PRECISION * temp2)
  134.     {
  135.     temp1 = (num / temp2) - temp2;
  136.     temp1 = abs (temp1);
  137.     temp2 = ((num / temp2) + temp2) / 2.0;
  138.     }
  139. return (temp2);
  140. }
  141.  
  142. double abs (x)          /* Absolute value of a double */
  143. double x;
  144. {
  145.  
  146. return (x < 0 ? -x : x);
  147. }
  148.  
  149. double dply (x)         /* Exercise some doubles */
  150. double x;
  151. {
  152. int i = TINY;
  153. double y;
  154.  
  155. while (i--)
  156.     {
  157.     y = x * x * x * x * x * x * x;
  158.     y = y / x / x / x / x / x / x;
  159.  
  160.     y = y + x + x + x + x + x + x;
  161.     y = y - x - x - x - x - x - x;
  162.     }
  163. return (y);
  164. }
  165.  
  166. unsigned fib (x)        /* Common Fibonacci function */
  167. int x;
  168. {
  169.  
  170. if (x > 2)
  171.     return (fib (x-1) + fib (x-2));
  172. else
  173.     return (1);
  174. }
  175.  
  176. int stest (b1,b2)       /* String test using strcpy() and strcmp() */
  177. char *b1, *b2;
  178. {
  179. int i,j;
  180. void mstrcpy ();
  181.  
  182. for (i = 0, j = 0; i < SMALL; ++i)
  183.     {
  184.     mstrcpy (b1, "0123456789abcdef");
  185.     mstrcpy (b2, "0123456789abcdee"); /* Note it's a different string. */
  186.     j += mstrcmp (b1,b2);
  187.     }
  188. return (j);
  189. }
  190.  
  191. int mstrcmp (c,d)       /* External string compare */
  192. char *c, *d;
  193. {
  194.  
  195. while (*c == *d)
  196.     {
  197.     if (!*c)
  198.         return (0);
  199.     ++c;
  200.     ++d;
  201.     }
  202. return (*c - *d);
  203. }
  204.  
  205. void mstrcpy (c,d)      /* External string copy */
  206. char *c, *d;
  207. {
  208.  
  209. while (*c++ = *d++)
  210.     ;
  211. }
  212.  
  213. int mcopy ()            /* Disk copy.  Test assumes file doesn't exist */
  214. {
  215. FILE *fp, *fopen ();
  216. char buf[TINY];
  217. int i, j;
  218.  
  219. mstrcpy (buf, "Disk I/O test");
  220. if ((fp = fopen(FILENAME,"w")) == NULL)
  221.     {
  222.     printf ("Cannot open file");
  223.     exit (ERR);
  224.     }
  225. i = 0;
  226. while (++i < LITTLE)
  227.     for (j = 0; buf[j]; ++j)
  228.         putc (buf[j], fp);
  229. fclose (fp);
  230. return (i);
  231. }
  232.  
  233. int intest ()           /* Square an integer by iteration */
  234. {
  235. int i, j, k, sum;
  236.  
  237. for (i = 0; i < LITTLE; ++i)
  238.     {
  239.     sum = 0;
  240.     for (j = 0, k = 1; j < MAXINT; ++j)
  241.         {
  242.         sum += k;
  243.         k += 2;
  244.         }
  245.     }
  246. return (sum);
  247. }
  248.