home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c221 / 5.ddi / MWHC.005 / E < prev    next >
Encoding:
Text File  |  1992-04-14  |  8.5 KB  |  366 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 whets();
  45.   long Wtime;
  46.  
  47.   printf("Code Benchmark               Iters     Time\n");
  48.   printf("--------------------------- -------  -------\n");
  49.   Wtime = DoBench("WS","Whetstone(single)",100L,whets);
  50.   if (Wtime) printf("  (%d KWhets/sec).\n",(int)(10000 / (Wtime/100.0))); 
  51.   exit(0);
  52. }
  53.  
  54. /**************************************************************************
  55.  *                                                                        *
  56.  *      Whetstone benchmark in C.  This program is a translation of the   *
  57.  *      original Algol version in "A Synthetic Benchmark" by H.J. Curnow  *
  58.  *      and B.A. Wichman in Computer Journal, Vol  19 #1, February 1976.  *
  59.  *                                                                        *
  60.  *      Used to test compiler efficiency, optimization, and double        *
  61.  *      precision floating-point performance.  This version is specific   *
  62.  *      to the Turbo-Amiga and Amiga but it can be easily adapted to      *
  63.  *      other systems by replacing the clock() routine with your own. *
  64.  *                                                                        *
  65.  **************************************************************************/
  66.  
  67. #define ITERATIONS   10       /* 1 Million Whetstone instructions    */
  68.  
  69. static long    j, k, l;
  70. static float    S_e1[4];
  71. static float    S_t, S_t1, S_t2; 
  72.  
  73. /* A true single-precision whestone can only be achieved by using
  74.    ANSI prototypes.  Without them, doubles get passed to p3 and converted
  75.    to float upon entry to p3.
  76.    If your compiler doesn't support prototypes, you could instead
  77.    pass pointers to x and y, for a slight decrease in efficiency.
  78. */   
  79.  
  80. #ifndef NO_PROTOTYPES
  81. S_p3(float,float,float*);
  82. #endif
  83.  
  84. whets() {
  85.  
  86.    long        i;
  87.    long     n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11;
  88.    long     m, loops;
  89.    float    S_x, S_y, S_z, S_x1, S_x2, S_x3, S_x4;
  90.    
  91.    /************************/
  92.    /* initialize constants */
  93.    /************************/
  94.  
  95.    S_t   =   0.499975;
  96.    S_t1  =   0.500250;
  97.    S_t2  =   2.0;
  98.  
  99.    /***********************/
  100.    /* Set Module Weights. */
  101.    /***********************/
  102.  
  103.    m = 10;                    /* m = 10 is used to obtain better timing  */
  104.    loops = m * ITERATIONS;    /* accuracy only.  Slow systems should use */
  105.    n1  =   0 * loops;         /* m = 1.                                  */
  106.    n2  =  12 * loops;
  107.    n3  =  14 * loops;
  108.    n4  = 345 * loops;
  109.    n5  =   0 * loops;
  110.    n6  = 210 * loops;
  111.    n7  =  32 * loops;
  112.    n8  = 899 * loops;
  113.    n9  = 616 * loops;
  114.    n10 =   0 * loops;
  115.    n11 =  93 * loops;
  116.  
  117.    /*********************************/
  118.    /* MODULE 1:  simple identifiers */
  119.    /*********************************/
  120.  
  121.    S_x1 =  1.0;
  122.    S_x2 = -1.0;
  123.    S_x3 = -1.0;
  124.    S_x4 = -1.0;
  125.  
  126.    if( n1 > 0 )
  127.    {
  128.      for(i = 1; i <= n1; i++)
  129.      {
  130.       S_x1 = ( S_x1 + S_x2 + S_x3 - S_x4 ) * S_t;
  131.       S_x2 = ( S_x1 + S_x2 - S_x3 - S_x4 ) * S_t;
  132.       S_x3 = ( S_x1 - S_x2 + S_x3 + S_x4 ) * S_t;
  133.       S_x4 = (-S_x1 + S_x2 + S_x3 + S_x4 ) * S_t;
  134.      }
  135.    }
  136.  
  137.    /*****************************/
  138.    /* MODULE 2:  Array Elements */
  139.    /*****************************/
  140.    S_e1[0] =  1.0;        /* Start at element 0 in C, vice 1 in Fortran */
  141.    S_e1[1] = -1.0;
  142.    S_e1[2] = -1.0;
  143.    S_e1[3] = -1.0;
  144.  
  145.    if( n2 > 0 )
  146.    {
  147.      for (i = 1; i <= n2; i++)
  148.      {
  149.       S_e1[0] = ( S_e1[0] + S_e1[1] + S_e1[2] - S_e1[3] ) * S_t;
  150.       S_e1[1] = ( S_e1[0] + S_e1[1] - S_e1[2] + S_e1[3] ) * S_t;
  151.       S_e1[2] = ( S_e1[0] - S_e1[1] + S_e1[2] + S_e1[3] ) * S_t;
  152.       S_e1[3] = (-S_e1[0] + S_e1[1] + S_e1[2] + S_e1[3] ) * S_t;
  153.      }
  154.    }
  155.  
  156.    /*********************************/
  157.    /* MODULE 3:  Array as Parameter */
  158.    /*********************************/
  159.    if( n3 > 0 )
  160.    {
  161.      for (i = 1; i <= n3; i++)
  162.      {
  163.       S_pa(S_e1);
  164.      }
  165.    }
  166.  
  167.    /********************************/
  168.    /* MODULE 4:  Conditional Jumps */
  169.    /********************************/
  170.    j = 1;
  171.  
  172.    if( n4 > 0 )
  173.    {
  174.      for (i = 1; i <= n4; i++)
  175.      {
  176.       if (j == 1)
  177.          j = 2;
  178.       else
  179.          j = 3;
  180.  
  181.       if (j > 2)
  182.          j = 0;
  183.       else
  184.          j = 1;
  185.  
  186.       if (j < 1 )
  187.          j = 1;
  188.       else
  189.          j = 0;
  190.      }
  191.    }
  192.  
  193.    /**********************/
  194.    /* MODULE 5:  Omitted */
  195.    /**********************/
  196.  
  197.  
  198.    /*********************************/
  199.    /* MODULE 6:  Integer Arithmetic */
  200.    /*********************************/
  201.    j = 1;
  202.    k = 2;
  203.    l = 3;
  204.  
  205.    if( n6 > 0 )
  206.    {
  207.      for (i = 1; i <= n6; i++)
  208.      {
  209.       j = j * (k - j) * (l -k);
  210.       k = l * k - (l - j) * k;
  211.       l = (l - k) * (k + j);
  212.  
  213.       S_e1[l - 2] = j + k + l;          /* Remember we started at S_e1[0]. */
  214.       S_e1[k - 2] = j * k * l;          /* l-2 in C, vice l-1 in Fortran */
  215.      }
  216.    }
  217.  
  218.    /**************************************/
  219.    /* MODULE 7:  Trigonometric Functions */
  220.    /**************************************/
  221.    S_x = 0.5;
  222.    S_y = 0.5;
  223.  
  224.    if( n7 > 0 )
  225.    {
  226.      for(i = 1; i <= n7; i++)
  227.      {
  228.       S_x = S_t * atan(S_t2*sin(S_x)*cos(S_x)/(cos(S_x+S_y)+cos(S_x-S_y)-1));
  229.       S_y = S_t * atan(S_t2*sin(S_y)*cos(S_y)/(cos(S_x+S_y)+cos(S_x-S_y)-1));
  230.      }
  231.    }
  232.  
  233.    /******************************/
  234.    /* MODULE 8:  Procedure Calls */
  235.    /******************************/
  236.  
  237.    S_x = 1.0;
  238.    S_y = 1.0;
  239.    S_z = 1.0;
  240.  
  241.    if( n8 > 0 )
  242.    {
  243.      for (i = 1; i <= n8; i++)
  244.      {
  245.       S_p3(S_x, S_y, &S_z);
  246.      }
  247.    }
  248.  
  249.    /*******************************/
  250.    /* MODULE 9:  Array References */
  251.    /*******************************/
  252.  
  253.    j = 1;
  254.    k = 2;
  255.    l = 3;
  256.  
  257.    S_e1[0] = 1.0;
  258.    S_e1[1] = 2.0;
  259.    S_e1[2] = 3.0;
  260.  
  261.    if( n9 > 0 )
  262.    {
  263.      for(i = 1; i <= n9; i++)
  264.      {
  265.       S_p0();
  266.      }
  267.    }
  268.  
  269.    /**********************************/
  270.    /* MODULE 10:  Integer Arithmetic */
  271.    /**********************************/
  272.  
  273.    j = 2;
  274.    k = 3;
  275.  
  276.    if( n10 > 0 )
  277.    {
  278.      for(i = 1; i <= n10; i++)
  279.      {
  280.       j = j + k;
  281.       k = j + k;
  282.       j = k - j;
  283.       k = k - j - j;
  284.      }
  285.    }
  286.  
  287.    /**********************************/
  288.    /* MODULE 11:  Standard Functions */
  289.    /**********************************/
  290.  
  291.    S_x = 0.75;
  292.  
  293.    if( n11 > 0 )
  294.    {
  295.      for(i = 1; i <= n11; i++)
  296.      {
  297.       S_x = sqrt( exp( log(S_x) / S_t1) );
  298.      }
  299.    }
  300.  
  301.    /**************************/
  302.    /* End of Whetstone Tests */
  303.    /**************************/
  304.  
  305. #if 0    /* Done elsewhere now. */
  306.    stoptime  = clock();
  307.    benchtime = stoptime - starttime - nulltime;
  308.    S_x1 = (double)benchtime/100.0;
  309.    printf("   Benchtime(sec) = %lf\n",S_x1);
  310.    S_x2 = 100.0 * (double)loops / S_x1;
  311.    KWhets = (long)S_x2;
  312.    printf("   KWhets/sec     = %ld\n\n",KWhets);
  313. #endif   
  314.  
  315. }
  316.  
  317. /*******************/
  318. /* Subroutine pa() */
  319. /*******************/
  320.  
  321. S_pa(e)                /* Exactly as in the Algol 60 version, but we */
  322.                      /* could do away with that 'goto'.            */
  323. float e[4];
  324.  
  325. {
  326.    int j;
  327.  
  328.    j = 0;
  329.      lab:
  330.    e[0] = (  e[0] + e[1] + e[2] - e[3] ) * S_t;
  331.    e[1] = (  e[0] + e[1] - e[2] + e[3] ) * S_t;
  332.    e[2] = (  e[0] - e[1] + e[2] + e[3] ) * S_t;
  333.    e[3] = ( -e[0] + e[1] + e[2] + e[3] ) / S_t2;
  334.    j ++;
  335.  
  336.    if (j < 6)
  337.       goto lab;
  338. }
  339.  
  340. /************************/
  341. /* Subroutine p3(x,y,z) */
  342. /************************/
  343.  
  344. S_p3(x, y, z)
  345.  
  346. float x, y, *z;
  347.  
  348. {
  349.    x  = S_t * (x + y);
  350.    y  = S_t * (x + y);
  351.    *z = (x + y) /S_t2;
  352. }
  353.  
  354. /*******************/
  355. /* Subroutine p0() */
  356. /*******************/
  357.  
  358. S_p0()
  359. {
  360.    S_e1[j] = S_e1[k];
  361.    S_e1[k] = S_e1[l];
  362.    S_e1[l] = S_e1[j];
  363. }
  364.  
  365. /*-- End Of Whetstone C Source Code -----------------*/
  366.