home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 10: Diskmags / nf_archive_10.iso / MAGS / SMARTMAG / V2.MSA / BENCHMRK.STQ_BENCHMRK.GST < prev    next >
Text File  |  2003-12-17  |  7KB  |  206 lines

  1. /***************************************************************************/
  2. /*                                                                         */
  3. /*  The Dhampstone Benchmark.  Written by Jack Purdum.   Ver. 1.0          */
  4. /*       Adapted for GST C by Arick Anders and Michael Bendio.             */
  5. /*                                                                         */
  6. /*  START magazine, Fall 1986.                                             */
  7. /*                                                                         */
  8. /*  The Dhampstone benchmark was first published in Computer Languages     */
  9. /*       February 1985.  It is used here by permission.                    */
  10. /*                                                                         */
  11. /***************************************************************************/
  12.         /*        version 1.0, August 1, 1985                       */
  13.  
  14. #include <stdio.h>
  15.  
  16. #define FIB         24
  17. #define TINY        100
  18. #define MAXINT      179
  19. #define LITTLE      1000
  20. #define SMALL       9000
  21. #define FILENAME    "zyxw.vut"
  22. #define NUMTEST     5
  23.  
  24. #define HOURS       4
  25. #define MINUTES     5
  26. #define SECONDS     6
  27.  
  28. #define void int
  29.  
  30.        int      cresult;
  31.        int      iresult;
  32.        int      cprsult;
  33.        unsigned uresult;
  34.        long     lresult;
  35.  
  36.        long       j;                 /* gst doesn't  support statics */
  37.        long dummy=1;
  38.  
  39.        main()
  40.        {
  41.            char buf1[TINY], buf2[TINY];
  42.            int i = 0;
  43.            long square, t, t2, keystroke;
  44.  
  45.            while ( keystroke = poll(dummy) ); /* clear keyboard buffer */
  46.            printf("Start...\n\n");
  47.  
  48.            while (i < NUMTEST) {
  49.               switch(i) {
  50.                  case (0):                             /* Character test  */
  51.                    t  = time();                   
  52.                    cresult = stest(buf1, buf2);
  53.                    t2 = time();
  54.                    printf("\ncharacter result = %d\n", cresult);
  55.                    printf("the time was = %d seconds\n", t2-t);
  56.                    break;
  57.                  case (1):
  58.                    t  = time();                   
  59.                    iresult = intest();         /* Integer test    */
  60.                    t2 = time();
  61.                    printf("\ninteger result = %d\n", iresult);
  62.                    printf("the time was = %d seconds\n", t2-t);
  63.                    break;
  64.                  case (2):
  65.                    t  = time();                   
  66.                    uresult = fib(FIB);         /* Unsigned test   */
  67.                    t2 = time();
  68.                    printf("\nfibonacci result = %u\n", uresult);
  69.                    printf("the time was = %d seconds\n", t2-t);
  70.                    break;
  71.                  case (3):
  72.                    square = 0;                 /* Long test       */
  73.                    t  = time();                   
  74.                    lresult = sq(square);
  75.                    square = sq(lresult);       /* Check the value */
  76.                    t2 = time();
  77.                    printf("\nlong result = %d\n", lresult);
  78.                    printf("square = %d\n", square);
  79.                    printf("the time was = %d seconds\n", t2-t);
  80.                    break;
  81.                  case (4):
  82.                    t  = time();
  83.                    cprsult = mcopy();          /* Disk copy      */
  84.                    t2 = time();
  85.                    printf("\nfile copy = %d\n", cprsult);
  86.                    printf("the time was = %d seconds\n", t2-t);
  87.                    break;
  88.                  default:
  89.                    break;
  90.               }
  91.               i++;
  92.            }                                            /* End while i    */
  93.            printf("\n\n...End");
  94.            dummy = getchar();
  95.         }
  96.  
  97. stest(b1, b2)      /* String test using strcpy() and strcmp() */
  98. char *b1, *b2;
  99.         {
  100.             int i, j;
  101.  
  102.             for (i = 0, j = 0; i < SMALL; ++i) {
  103.                 mstrcpy(b1, "0123456789abcdef");
  104.                 mstrcpy(b2, "0123456789abcdee");   /* Note it's a */
  105.                 j += mstrcmp(b1, b2);              /* different string */
  106.             }
  107.  
  108.             return (j);
  109.         }
  110.  
  111. mstrcmp(c, d)                /* External string compare */
  112. char *c, *d;
  113.         {
  114.             while (*c == *d) {
  115.                   if (!*c)
  116.                      return (0);
  117.                   ++c;
  118.                   ++d;
  119.            }
  120.            return (*c - *d);
  121.         }
  122.  
  123. mstrcpy(c, d)       /* External string copy */
  124. char *c, *d;
  125.         {
  126.             while (*c++ = *d++)
  127.                      ;
  128.         }
  129.  
  130. intest()            /* Square an integer by iteration */
  131.         {
  132.                 int i, j, k, sum;
  133.  
  134.                 for (i = 0; i < LITTLE; ++i) {
  135.                         sum = 0;
  136.                         for (j = 0, k = 1; j < MAXINT; ++j) {
  137.                                 sum += k;
  138.                                 k += 2;
  139.                         }
  140.                 }
  141.                 return (sum);
  142.         }
  143.  
  144. sq(big)          /* Function to square a number by iteration */
  145. long big;
  146.         {
  147.             int i;
  148.             j = 1;
  149.  
  150.             if (!big)
  151.                for (i = 0; i < SMALL; ++i) {
  152.                    big += j;
  153.                    j += 2;
  154.                }
  155.             else
  156.                 for (i = 0; i < SMALL; ++i) {
  157.                     j -= 2;
  158.                     big -= j;
  159.                 }
  160.             return (big);
  161.         }
  162.  
  163.  
  164. fib(x)          /* Common Fibonacci function */
  165. int x;
  166.         {
  167.             if (x > 2)
  168.                 return ( fib(x -1) + fib(x - 2));
  169.             else
  170.                 return (1);
  171.         }
  172.  
  173.  
  174. mcopy()         /* Disk copy. Test assumes file doesn't exist */
  175.         {
  176.             FILE *fp;
  177.             char buf[TINY];
  178.             int i, j;
  179.  
  180.             mstrcpy(buf, "Disk I/O test");
  181.  
  182.             if ((fp = fopen(FILENAME, "w")) == NULL) {
  183.                printf("Cannot open file");
  184.                exit(-1);
  185.             }
  186.  
  187.             i = 0;
  188.  
  189.             while (++i < LITTLE)
  190.                   for (j = 0; buf[j]; ++j)
  191.                       putc(buf[j], fp);
  192.  
  193.             fclose(fp);
  194.             return (i);
  195.         }
  196.  
  197.  
  198. time()
  199. {
  200. int datetime[7];
  201.  
  202. date(dummy, datetime);
  203. return( datetime[HOURS]*3600 + datetime[MINUTES]*60 + datetime[SECONDS] );
  204. }
  205.  
  206.