home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c221 / 5.ddi / MWHC.005 / D < prev    next >
Encoding:
Text File  |  1992-04-14  |  8.1 KB  |  355 lines

  1. #ifdef __HIGHC__
  2. #  pragma wtrsvd1(16);    /* New Intel setting for Weitek registers. */
  3. #  pragma on(align_labels);
  4. #else
  5. #  define NO_PROTOTYPES
  6. #endif
  7.  
  8.  
  9. #include <stdio.h>
  10. #include <math.h>
  11. #include <time.h>
  12.  
  13.  
  14.  
  15. long DoBench(bname, strp, liters, funcp)
  16. char *bname;
  17. char *strp;            /* Pointer to benchmark name */
  18. long liters;            /* Number of iterations */    
  19. int (*funcp)();            /* Pointer to benchmark function */
  20. {
  21.  
  22.   long stime;        /* Start time */
  23.   long etime;        /* End time */
  24.   long time;        /* Elapse time */
  25.   int secs;        /* Seconds */
  26.   int hunds;        /* 1/100 seconds */
  27.  
  28.   printf("%4s %-22s  %6d  ", bname, strp, liters);
  29.   stime = clock();
  30.   (*funcp)();
  31.   etime = clock();
  32.   time = etime - stime;
  33.   time = (long)(time / (CLOCKS_PER_SEC/60.0));
  34.   secs = time / 100;
  35.   hunds = time % 100;
  36.   printf("%4d.%02d secs\n", secs, hunds);
  37.   return time;
  38. }
  39.  
  40.  
  41. main()
  42. {
  43.  
  44.   extern whetd();
  45.   long Wtime;
  46.  
  47.   printf("Code Benchmark               Iters     Time\n");
  48.   printf("--------------------------- -------  -------\n");
  49.   Wtime = DoBench("WD","Whetstone (double)",100L,whetd);
  50.   if (Wtime) printf("  (%d KWhets/sec).\n",(int)(10000 / (Wtime/100.0)));
  51.  
  52.   exit(0);
  53. }
  54.  
  55. /**************************************************************************
  56.  *                                                                        *
  57.  *      Whetstone benchmark in C.  This program is a translation of the   *
  58.  *      original Algol version in "A Synthetic Benchmark" by H.J. Curnow  *
  59.  *      and B.A. Wichman in Computer Journal, Vol  19 #1, February 1976.  *
  60.  *                                                                        *
  61.  *      Used to test compiler efficiency, optimization, and double        *
  62.  *      precision floating-point performance.  This version is specific   *
  63.  *      to the Turbo-Amiga and Amiga but it can be easily adapted to      *
  64.  *      other systems by replacing the clock() routine with your own. *
  65.  *                                                                        *
  66.  **************************************************************************/
  67.  
  68. #define ITERATIONS   10       /* 1 Million Whetstone instructions    */
  69.  
  70. static double   D_e1[4];
  71. static double   D_t, D_t1, D_t2;
  72. static long     j, k, l;
  73.  
  74. whetd() {
  75.  
  76.    long        i;
  77.    long     n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11;
  78.    long     m, loops;
  79.    double   D_x, D_y, D_z, D_x1, D_x2, D_x3, D_x4;
  80.    
  81.    /************************/
  82.    /* initialize constants */
  83.    /************************/
  84.  
  85.    D_t   =   0.499975;
  86.    D_t1  =   0.500250;
  87.    D_t2  =   2.0;
  88.  
  89.    /***********************/
  90.    /* Set Module Weights. */
  91.    /***********************/
  92.  
  93.    m = 10;                    /* m = 10 is used to obtain better timing  */
  94.    loops = m * ITERATIONS;    /* accuracy only.  Slow systems should use */
  95.    n1  =   0 * loops;         /* m = 1.                                  */
  96.    n2  =  12 * loops;
  97.    n3  =  14 * loops;
  98.    n4  = 345 * loops;
  99.    n5  =   0 * loops;
  100.    n6  = 210 * loops;
  101.    n7  =  32 * loops;
  102.    n8  = 899 * loops;
  103.    n9  = 616 * loops;
  104.    n10 =   0 * loops;
  105.    n11 =  93 * loops;
  106.  
  107.    /*********************************/
  108.    /* MODULE 1:  simple identifiers */
  109.    /*********************************/
  110.  
  111.    D_x1 =  1.0;
  112.    D_x2 = -1.0;
  113.    D_x3 = -1.0;
  114.    D_x4 = -1.0;
  115.  
  116.    if( n1 > 0 )
  117.    {
  118.      for(i = 1; i <= n1; i++)
  119.      {
  120.       D_x1 = ( D_x1 + D_x2 + D_x3 - D_x4 ) * D_t;
  121.       D_x2 = ( D_x1 + D_x2 - D_x3 - D_x4 ) * D_t;
  122.       D_x3 = ( D_x1 - D_x2 + D_x3 + D_x4 ) * D_t;
  123.       D_x4 = (-D_x1 + D_x2 + D_x3 + D_x4 ) * D_t;
  124.      }
  125.    }
  126.  
  127.    /*****************************/
  128.    /* MODULE 2:  Array Elements */
  129.    /*****************************/
  130.    D_e1[0] =  1.0;        /* Start at element 0 in C, vice 1 in Fortran */
  131.    D_e1[1] = -1.0;
  132.    D_e1[2] = -1.0;
  133.    D_e1[3] = -1.0;
  134.  
  135.    if( n2 > 0 )
  136.    {
  137.      for (i = 1; i <= n2; i++)
  138.      {
  139.       D_e1[0] = ( D_e1[0] + D_e1[1] + D_e1[2] - D_e1[3] ) * D_t;
  140.       D_e1[1] = ( D_e1[0] + D_e1[1] - D_e1[2] + D_e1[3] ) * D_t;
  141.       D_e1[2] = ( D_e1[0] - D_e1[1] + D_e1[2] + D_e1[3] ) * D_t;
  142.       D_e1[3] = (-D_e1[0] + D_e1[1] + D_e1[2] + D_e1[3] ) * D_t;
  143.      }
  144.    }
  145.  
  146.    /*********************************/
  147.    /* MODULE 3:  Array as Parameter */
  148.    /*********************************/
  149.    if( n3 > 0 )
  150.    {
  151.      for (i = 1; i <= n3; i++)
  152.      {
  153.       D_pa(D_e1);
  154.      }
  155.    }
  156.  
  157.    /********************************/
  158.    /* MODULE 4:  Conditional Jumps */
  159.    /********************************/
  160.    j = 1;
  161.  
  162.    if( n4 > 0 )
  163.    {
  164.      for (i = 1; i <= n4; i++)
  165.      {
  166.       if (j == 1)
  167.          j = 2;
  168.       else
  169.          j = 3;
  170.  
  171.       if (j > 2)
  172.          j = 0;
  173.       else
  174.          j = 1;
  175.  
  176.       if (j < 1 )
  177.          j = 1;
  178.       else
  179.          j = 0;
  180.      }
  181.    }
  182.  
  183.    /**********************/
  184.    /* MODULE 5:  Omitted */
  185.    /**********************/
  186.  
  187.  
  188.    /*********************************/
  189.    /* MODULE 6:  Integer Arithmetic */
  190.    /*********************************/
  191.    j = 1;
  192.    k = 2;
  193.    l = 3;
  194.  
  195.    if( n6 > 0 )
  196.    {
  197.      for (i = 1; i <= n6; i++)
  198.      {
  199.       j = j * (k - j) * (l -k);
  200.       k = l * k - (l - j) * k;
  201.       l = (l - k) * (k + j);
  202.  
  203.       D_e1[l - 2] = j + k + l;          /* Remember we started at D_e1[0]. */
  204.       D_e1[k - 2] = j * k * l;          /* l-2 in C, vice l-1 in Fortran */
  205.      }
  206.    }
  207.  
  208.    /**************************************/
  209.    /* MODULE 7:  Trigonometric Functions */
  210.    /**************************************/
  211.    D_x = 0.5;
  212.    D_y = 0.5;
  213.  
  214.    if( n7 > 0 )
  215.    {
  216.      for(i = 1; i <= n7; i++)
  217.      {
  218.       D_x = D_t * atan(D_t2*sin(D_x)*cos(D_x)/(cos(D_x+D_y)+cos(D_x-D_y)-1.0));
  219.       D_y = D_t * atan(D_t2*sin(D_y)*cos(D_y)/(cos(D_x+D_y)+cos(D_x-D_y)-1.0));
  220.      }
  221.    }
  222.  
  223.    /******************************/
  224.    /* MODULE 8:  Procedure Calls */
  225.    /******************************/
  226.  
  227.    D_x = 1.0;
  228.    D_y = 1.0;
  229.    D_z = 1.0;
  230.  
  231.    if( n8 > 0 )
  232.    {
  233.      for (i = 1; i <= n8; i++)
  234.      {
  235.       D_p3(D_x, D_y, &D_z);
  236.      }
  237.    }
  238.  
  239.    /*******************************/
  240.    /* MODULE 9:  Array References */
  241.    /*******************************/
  242.  
  243.    j = 1;
  244.    k = 2;
  245.    l = 3;
  246.  
  247.    D_e1[0] = 1.0;
  248.    D_e1[1] = 2.0;
  249.    D_e1[2] = 3.0;
  250.  
  251.    if( n9 > 0 )
  252.    {
  253.      for(i = 1; i <= n9; i++)
  254.      {
  255.       D_p0();
  256.      }
  257.    }
  258.  
  259.    /**********************************/
  260.    /* MODULE 10:  Integer Arithmetic */
  261.    /**********************************/
  262.  
  263.    j = 2;
  264.    k = 3;
  265.  
  266.    if( n10 > 0 )
  267.    {
  268.      for(i = 1; i <= n10; i++)
  269.      {
  270.       j = j + k;
  271.       k = j + k;
  272.       j = k - j;
  273.       k = k - j - j;
  274.      }
  275.    }
  276.  
  277.    /**********************************/
  278.    /* MODULE 11:  Standard Functions */
  279.    /**********************************/
  280.  
  281.    D_x = 0.75;
  282.  
  283.    if( n11 > 0 )
  284.    {
  285.      for(i = 1; i <= n11; i++)
  286.      {
  287.       D_x = sqrt( exp( log(D_x) / D_t1) );
  288.      }
  289.    }
  290.  
  291.    /**************************/
  292.    /* End of Whetstone Tests */
  293.    /**************************/
  294.  
  295. #if 0    /* Done elsewhere now. */
  296.    stoptime  = clock();
  297.    benchtime = stoptime - starttime - nulltime;
  298.    D_x1 = (double)benchtime/100.0;
  299.    printf("   Benchtime(sec) = %lf\n",D_x1);
  300.    D_x2 = 100.0 * (double)loops / D_x1;
  301.    KWhets = (long)D_x2;
  302.    printf("   KWhets/sec     = %ld\n\n",KWhets);
  303. #endif   
  304.  
  305. }
  306.  
  307. /*******************/
  308. /* Subroutine pa() */
  309. /*******************/
  310.  
  311. D_pa(e)                /* Exactly as in the Algol 60 version, but we */
  312.                      /* could do away with that 'goto'.            */
  313. double e[4];
  314.  
  315. {
  316.    int j;
  317.  
  318.    j = 0;
  319.      lab:
  320.    e[0] = (  e[0] + e[1] + e[2] - e[3] ) * D_t;
  321.    e[1] = (  e[0] + e[1] - e[2] + e[3] ) * D_t;
  322.    e[2] = (  e[0] - e[1] + e[2] + e[3] ) * D_t;
  323.    e[3] = ( -e[0] + e[1] + e[2] + e[3] ) / D_t2;
  324.    j ++;
  325.  
  326.    if (j < 6)
  327.       goto lab;
  328. }
  329.  
  330. /************************/
  331. /* Subroutine p3(x,y,z) */
  332. /************************/
  333.  
  334. D_p3(x, y, z)
  335.  
  336. double x, y, *z;
  337.  
  338. {
  339.    x  = D_t * (x + y);
  340.    y  = D_t * (x + y);
  341.    *z = (x + y) /D_t2;
  342. }
  343.  
  344. /*******************/
  345. /* Subroutine p0() */
  346. /*******************/
  347.  
  348. D_p0()
  349. {
  350.    D_e1[j] = D_e1[k];
  351.    D_e1[k] = D_e1[l];
  352.    D_e1[l] = D_e1[j];
  353. }
  354.  
  355.