home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c221 / 5.ddi / MWHC.005 / Y < prev    next >
Encoding:
Text File  |  1992-03-30  |  14.7 KB  |  654 lines

  1. /**************************************************************************
  2.  *                                                                        *
  3.  *      Whetstone benchmark in C.  This program is a translation of the   *
  4.  *      original Algol version in "A Synthetic Benchmark" by H.J. Curnow  *
  5.  *      and B.A. Wichman in Computer Journal, Vol  19 #1, February 1976.  *
  6.  *                                                                        *
  7.  *      Used to test compiler efficiency, optimization, and double        *
  8.  *      precision floating-point performance.  This version is specific   *
  9.  *      to the Turbo-Amiga and Amiga but it can be easily adapted to      *
  10.  *      other systems by replacing the timeticks() routine with your own. *
  11.  *                                                                        *
  12.  **************************************************************************/
  13.  
  14. #include <system.cf>        /* For High C timings.  */
  15. /* Specify pragma on(387); for the best High C timings with a 387. */
  16.  
  17. #define ITERATIONS   10       /* 1 Million Whetstone instructions    */
  18.  
  19. /* #define POUT  */           /* Leave as is for 'Official' result.  */
  20.  
  21. /* #define MTEST */           /* define for Module timing results    */
  22.                               /* only.  Leave as is for 'Official'   */
  23.                               /* result.                             */
  24.  
  25. double   e1[4],e2[4];
  26. double   t, t1, t2, x, y, z, x1, x2, x3, x4;
  27. long     i, j, k, l;
  28. long     n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11;
  29. long     m, m1, m2, loops, KWhets;
  30.  
  31. long  starttime, stoptime, nulltime;
  32. long  sumtime, benchtime,timeticks();     /* Replace timeticks() with */
  33.                                           /* your own system timing   */
  34.                                           /* routine.                 */
  35. #include <math.h>
  36.  
  37. main()
  38. {
  39.    printf("\n   Whetstone C Benchmark V1.0\n");
  40.  
  41.    starttime = timeticks();               /* Calculate timer call delay */
  42.    stoptime  = timeticks();
  43.    nulltime  = stoptime - starttime;
  44.  
  45.    /************************/
  46.    /* initialize constants */
  47.    /************************/
  48.  
  49.    t   =   0.499975;
  50.    t1  =   0.500250;
  51.    t2  =   2.0;
  52.  
  53.    /***********************/
  54.    /* Set Module Weights. */
  55.    /***********************/
  56.  
  57.    m = 10;                    /* m = 10 is used to obtain better timing  */
  58.    loops = m * ITERATIONS;    /* accuracy only.  Slow systems should use */
  59.    n1  =   0 * loops;         /* m = 1.                                  */
  60.    n2  =  12 * loops;
  61.    n3  =  14 * loops;
  62.    n4  = 345 * loops;
  63.    n5  =   0 * loops;
  64.    n6  = 210 * loops;
  65.    n7  =  32 * loops;
  66.    n8  = 899 * loops;
  67.    n9  = 616 * loops;
  68.    n10 =   0 * loops;
  69.    n11 =  93 * loops;
  70.  
  71.  
  72.                               /* Start Timing the Whetstone here. */
  73.    starttime = timeticks();
  74.  
  75.    /*********************************/
  76.    /* MODULE 1:  simple identifiers */
  77.    /*********************************/
  78.  
  79.    x1 =  1.0;
  80.    x2 = -1.0;
  81.    x3 = -1.0;
  82.    x4 = -1.0;
  83.  
  84.    if( n1 > 0 )
  85.    {
  86.      for(i = 1; i <= n1; i++)
  87.      {
  88.       x1 = ( x1 + x2 + x3 - x4 ) * t;
  89.       x2 = ( x1 + x2 - x3 - x4 ) * t;
  90.       x3 = ( x1 - x2 + x3 + x4 ) * t;
  91.       x4 = (-x1 + x2 + x3 + x4 ) * t;
  92.      }
  93.    }
  94.  
  95. #ifdef MTEST                                    /* Module 1 Run Time */
  96.    stoptime  = timeticks();
  97.    benchtime = stoptime - starttime - nulltime;
  98.    m = 1;
  99.    x = (double)benchtime/50.0;
  100.    printf("   End Module %ld.   Benchtime(sec) = %lf\n",m,x);
  101. #endif
  102.  
  103. #ifdef POUT
  104.    Pout(n1, n1, n1, x1, x2, x3, x4);
  105. #endif
  106.  
  107.    /*****************************/
  108.    /* MODULE 2:  Array Elements */
  109.    /*****************************/
  110. #ifdef MTEST
  111.    starttime = timeticks();
  112. #endif
  113.  
  114.    e1[0] =  1.0;        /* Start at element 0 in C, vice 1 in Fortran */
  115.    e1[1] = -1.0;
  116.    e1[2] = -1.0;
  117.    e1[3] = -1.0;
  118.  
  119.    if( n2 > 0 )
  120.    {
  121.      for (i = 1; i <= n2; i++)
  122.      {
  123.       e1[0] = ( e1[0] + e1[1] + e1[2] - e1[3] ) * t;
  124.       e1[1] = ( e1[0] + e1[1] - e1[2] + e1[3] ) * t;
  125.       e1[2] = ( e1[0] - e1[1] + e1[2] + e1[3] ) * t;
  126.       e1[3] = (-e1[0] + e1[1] + e1[2] + e1[3] ) * t;
  127.      }
  128.    }
  129.  
  130. #ifdef MTEST
  131.    stoptime  = timeticks();
  132.    benchtime = stoptime - starttime - nulltime;
  133.    sumtime   = benchtime;
  134.    m = 2;
  135.    x = (double)benchtime/50.0;
  136.    printf("   End Module %ld.   Benchtime(sec) = %lf\n",m,x);
  137. #endif
  138.  
  139. #ifdef POUT
  140.    Pout(n2, n3, n2, e1[0], e1[1], e1[2], e1[3]);
  141. #endif
  142.  
  143.    /*********************************/
  144.    /* MODULE 3:  Array as Parameter */
  145.    /*********************************/
  146. #ifdef MTEST
  147.    starttime = timeticks();
  148. #endif
  149.  
  150.    if( n3 > 0 )
  151.    {
  152.      for (i = 1; i <= n3; i++)
  153.      {
  154.       pa(e1);
  155.      }
  156.    }
  157.  
  158. #ifdef MTEST
  159.    stoptime  = timeticks();
  160.    benchtime = stoptime - starttime - nulltime;
  161.    m1 = benchtime;
  162.    m = 3;
  163.    x = (double)benchtime/50.0;
  164.    printf("   End Module %ld.   Benchtime(sec) = %lf\n",m,x);
  165. #endif
  166.  
  167. #ifdef POUT
  168.    Pout(n3, n2, n2, e1[0], e1[1], e1[2], e1[3]);
  169. #endif
  170.  
  171.    /********************************/
  172.    /* MODULE 4:  Conditional Jumps */
  173.    /********************************/
  174. #ifdef MTEST
  175.    starttime = timeticks();
  176. #endif
  177.  
  178.    j = 1;
  179.  
  180.    if( n4 > 0 )
  181.    {
  182.      for (i = 1; i <= n4; i++)
  183.      {
  184.       if (j == 1)
  185.          j = 2;
  186.       else
  187.          j = 3;
  188.  
  189.       if (j > 2)
  190.          j = 0;
  191.       else
  192.          j = 1;
  193.  
  194.       if (j < 1 )
  195.          j = 1;
  196.       else
  197.          j = 0;
  198.      }
  199.    }
  200.  
  201. #ifdef MTEST
  202.    stoptime  = timeticks();
  203.    benchtime = stoptime - starttime - nulltime;
  204.    sumtime   = sumtime + benchtime;
  205.    m = 4;
  206.    x = (double)benchtime/50.0;
  207.    printf("   End Module %ld.   Benchtime(sec) = %lf\n",m,x);
  208.    starttime = timeticks();
  209. #endif
  210.  
  211. #ifdef POUT
  212.    Pout(n4, j, j, x1, x2, x3, x4);
  213. #endif
  214.  
  215.    /**********************/
  216.    /* MODULE 5:  Omitted */
  217.    /**********************/
  218.  
  219.  
  220. #ifdef MTEST
  221.    benchtime = 0;
  222.    m = 5;
  223.    x = 0.0;
  224.    printf("   End Module %ld.   Benchtime(sec) = %lf\n",m,x);
  225. #endif
  226.  
  227. #ifdef POUT
  228.    Pout(n4, j, j, x1, x2, x3, x4);
  229. #endif
  230.  
  231.    /*********************************/
  232.    /* MODULE 6:  Integer Arithmetic */
  233.    /*********************************/
  234. #ifdef MTEST
  235.    starttime = timeticks();
  236. #endif
  237.  
  238.    j = 1;
  239.    k = 2;
  240.    l = 3;
  241.  
  242.    if( n6 > 0 )
  243.    {
  244.      for (i = 1; i <= n6; i++)
  245.      {
  246.       j = j * (k - j) * (l -k);
  247.       k = l * k - (l - j) * k;
  248.       l = (l - k) * (k + j);
  249.  
  250.       e1[l - 2] = j + k + l;          /* Remember we started at e1[0]. */
  251.       e1[k - 2] = j * k * l;          /* l-2 in C, vice l-1 in Fortran */
  252.      }
  253.    }
  254.  
  255. #ifdef MTEST
  256.    stoptime  = timeticks();
  257.    benchtime = stoptime - starttime - nulltime;
  258.    sumtime   = sumtime + benchtime;
  259.    m = 6;
  260.    x = (double)benchtime/50.0;
  261.    printf("   End Module %ld.   Benchtime(sec) = %lf\n",m,x);
  262. #endif
  263.  
  264. #ifdef POUT
  265.    Pout(n6, j, k, e1[0], e1[1], e1[2], e1[3]);
  266. #endif
  267.  
  268.    /**************************************/
  269.    /* MODULE 7:  Trigonometric Functions */
  270.    /**************************************/
  271. #ifdef MTEST
  272.    starttime = timeticks();
  273. #endif
  274.  
  275.    x = 0.5;
  276.    y = 0.5;
  277.  
  278.    if( n7 > 0 )
  279.    {
  280.      for(i = 1; i <= n7; i++)
  281.      {
  282.       x = t * atan(t2*sin(x)*cos(x)/(cos(x+y)+cos(x-y)-1.0));
  283.       y = t * atan(t2*sin(y)*cos(y)/(cos(x+y)+cos(x-y)-1.0));
  284.      }
  285.    }
  286.  
  287. #ifdef MTEST
  288.    stoptime  = timeticks();
  289.    benchtime = stoptime - starttime - nulltime;
  290.    sumtime   = sumtime + benchtime;
  291.    m = 7;
  292.    x1 = (double)benchtime/50.0;
  293.    printf("   End Module %ld.   Benchtime(sec) = %lf\n",m,x1);
  294. #endif
  295.  
  296. #ifdef POUT
  297.    Pout(n7, j, k, x, x, y, y);
  298. #endif
  299.  
  300.    /******************************/
  301.    /* MODULE 8:  Procedure Calls */
  302.    /******************************/
  303. #ifdef MTEST
  304.    starttime = timeticks();
  305. #endif
  306.  
  307.    x = 1.0;
  308.    y = 1.0;
  309.    z = 1.0;
  310.  
  311.    if( n8 > 0 )
  312.    {
  313.      for (i = 1; i <= n8; i++)
  314.      {
  315.       p3(x, y, &z);
  316.      }
  317.    }
  318.  
  319. #ifdef MTEST
  320.    stoptime  = timeticks();
  321.    benchtime = stoptime - starttime - nulltime;
  322.    m1 = m1 + benchtime;
  323.    m = 8;
  324.    x1 = (double)benchtime/50.0;
  325.    printf("   End Module %ld.   Benchtime(sec) = %lf\n",m,x1);
  326. #endif
  327.  
  328. #ifdef POUT
  329.    Pout(n8, j, k, x, y, z, z);
  330. #endif
  331.  
  332.    /*******************************/
  333.    /* MODULE 9:  Array References */
  334.    /*******************************/
  335. #ifdef MTEST
  336.    starttime = timeticks();
  337. #endif
  338.  
  339.    j = 1;
  340.    k = 2;
  341.    l = 3;
  342.  
  343.    e1[0] = 1.0;
  344.    e1[1] = 2.0;
  345.    e1[2] = 3.0;
  346.  
  347.    if( n9 > 0 )
  348.    {
  349.      for(i = 1; i <= n9; i++)
  350.      {
  351.       p0();
  352.      }
  353.    }
  354.  
  355. #ifdef MTEST
  356.    stoptime  = timeticks();
  357.    benchtime = stoptime - starttime - nulltime;
  358.    m1 = m1 + benchtime;
  359.    m = 9;
  360.    x = (double)benchtime/50.0;
  361.    printf("   End Module %ld.   Benchtime(sec) = %lf\n",m,x);
  362. #endif
  363.  
  364. #ifdef POUT
  365.    Pout(n9, j, k, e1[0], e1[1], e1[2], e1[3]);
  366. #endif
  367.  
  368.    /**********************************/
  369.    /* MODULE 10:  Integer Arithmetic */
  370.    /**********************************/
  371. #ifdef MTEST
  372.    starttime = timeticks();
  373. #endif
  374.  
  375.    j = 2;
  376.    k = 3;
  377.  
  378.    if( n10 > 0 )
  379.    {
  380.      for(i = 1; i <= n10; i++)
  381.      {
  382.       j = j + k;
  383.       k = j + k;
  384.       j = k - j;
  385.       k = k - j - j;
  386.      }
  387.    }
  388.  
  389. #ifdef MTEST
  390.    stoptime  = timeticks();
  391.    benchtime = 0;
  392.    m = 10;
  393.    x = 0.0;
  394.    printf("   End Module %ld.  Benchtime(sec) = %lf\n",m,x);
  395. #endif
  396.  
  397. #ifdef POUT
  398.    Pout(n10, j, k, x1, x2, x3, x4);
  399. #endif
  400.  
  401.    /**********************************/
  402.    /* MODULE 11:  Standard Functions */
  403.    /**********************************/
  404. #ifdef MTEST
  405.    starttime = timeticks();
  406. #endif
  407.  
  408.    x = 0.75;
  409.  
  410.    if( n11 > 0 )
  411.    {
  412.      for(i = 1; i <= n11; i++)
  413.      {
  414.       x = sqrt( exp( log(x) / t1) );
  415.      }
  416.    }
  417.  
  418. #ifdef MTEST
  419.    stoptime  = timeticks();
  420.    benchtime = stoptime - starttime - nulltime;
  421.    sumtime   = sumtime + benchtime;
  422.    m = 11;
  423.    x1 = (double)benchtime/50.0;
  424.    printf("   End Module %ld.  Benchtime(sec) = %lf\n\n",m,x1);
  425. #endif
  426.  
  427. #ifdef POUT
  428.    Pout(n11, j, k, x, x, x, x);
  429. #endif
  430.  
  431.    /********************************************************/
  432.    /* MODULE 12:  Array as a Parameter.                    */
  433.    /* Same as Module 3 except Subroutine overhead removed. */
  434.    /********************************************************/
  435.  
  436. #ifdef MTEST
  437.  
  438.    starttime = timeticks();
  439.    if( n3 > 0 )
  440.    {
  441.      for (i = 1; i <= n3; i++)
  442.      {
  443.       j = 0;
  444.         lab:
  445.       e2[0] = (  e2[0] + e2[1] + e2[2] - e2[3] ) * t;
  446.       e2[1] = (  e2[0] + e2[1] - e2[2] + e2[3] ) * t;
  447.       e2[2] = (  e2[0] - e2[1] + e2[2] + e2[3] ) * t;
  448.       e2[3] = ( -e2[0] + e2[1] + e2[2] + e2[3] ) /t2;
  449.       j++;
  450.  
  451.       if (j < 6)
  452.          goto lab;
  453.      }
  454.    }
  455.  
  456.    stoptime  = timeticks();
  457.    benchtime = stoptime - starttime - nulltime;
  458.    m2   = benchtime;
  459.    m = 3;
  460.    x1 = (double)benchtime/50.0;
  461.    printf("   End Module %ld.   Benchtime(sec) = %lf\n",m,x1);
  462.  
  463. #endif
  464.  
  465. #ifdef POUT
  466.    Pout(n11, j, k, x, x, x, x);
  467. #endif
  468.  
  469.    /********************************************************/
  470.    /* MODULE 13:  Array as a Parameter.                    */
  471.    /* Same as Module 8 except Subroutine overhead removed. */
  472.    /********************************************************/
  473.  
  474. #ifdef MTEST
  475.  
  476.    starttime = timeticks();
  477.    x = 1.0;
  478.    y = 1.0;
  479.    z = 1.0;
  480.  
  481.    if( n8 > 0 )
  482.    {
  483.      for (i = 1; i <= n8; i++)
  484.      {
  485.       x = t * (x + y);
  486.       y = t * (x + y);
  487.       z = (x + y) /t2;
  488.      }
  489.    }
  490.  
  491.    stoptime  = timeticks();
  492.    benchtime = stoptime - starttime - nulltime;
  493.    m2   = m2 + benchtime;
  494.    m = 8;
  495.    x1 = (double)benchtime/50.0;
  496.    printf("   End Module %ld.   Benchtime(sec) = %lf\n",m,x1);
  497.  
  498. #endif
  499.  
  500. #ifdef POUT
  501.    Pout(n11, j, k, x, x, x, x);
  502. #endif
  503.  
  504.    /********************************************************/
  505.    /* MODULE 14:  Array as a Parameter.                    */
  506.    /* Same as Module 9 except Subroutine overhead removed. */
  507.    /********************************************************/
  508.  
  509. #ifdef MTEST
  510.  
  511.    starttime = timeticks();
  512.    j = 1;
  513.    k = 2;
  514.    l = 3;
  515.  
  516.    e1[0] = 1.0;
  517.    e1[1] = 2.0;
  518.    e1[2] = 3.0;
  519.  
  520.    if( n9 > 0 )
  521.    {
  522.      for(i = 1; i <= n9; i++)
  523.      {
  524.       e1[j] = e1[k];
  525.       e1[k] = e1[l];
  526.       e1[l] = e1[j];
  527.      }
  528.    }
  529.  
  530.    stoptime  = timeticks();
  531.    benchtime = stoptime - starttime - nulltime;
  532.    m2 = m2 + benchtime;
  533.    m = 9;
  534.    x1 = (double)benchtime/50.0;
  535.    printf("   End Module %ld.   Benchtime(sec) = %lf\n",m,x1);
  536.  
  537. #endif
  538.  
  539. #ifdef POUT
  540.    Pout(n11, j, k, x, x, x, x);
  541. #endif
  542.  
  543.    /**************************/
  544.    /* End of Whetstone Tests */
  545.    /**************************/
  546.  
  547. #ifdef MTEST
  548.    m1 = m1 + sumtime;
  549.    m2 = m2 + sumtime;
  550.    x1 = (double)m1/50.0;
  551.    x2 = (double)m2/50.0;
  552.  
  553.    printf("Standard Whetstone Result\n");
  554.    printf("   Benchtime(sec) = %lf\n",x1);
  555.    x  = 100.0 * (double)loops / x1;
  556.    KWhets = (long)x;
  557.    printf("   KWhets/sec     = %ld\n",KWhets);
  558.  
  559.    printf("Result with subroutine call replaced with subroutine code\n");
  560.    printf("   Benchtime(sec) = %lf\n",x2);
  561.    x  = 100.0 * (double)loops / x2;
  562.    KWhets = (long)x;
  563.    printf("   KWhets/sec     = %ld\n",KWhets);
  564.  
  565. #else
  566.  
  567.    stoptime  = timeticks();
  568.    benchtime = stoptime - starttime - nulltime;
  569.    x1 = (double)benchtime/50.0;
  570.    printf("   Benchtime(sec) = %lf\n",x1);
  571.    x2 = 100.0 * (double)loops / x1;
  572.    KWhets = (long)x2;
  573.    printf("   KWhets/sec     = %ld\n\n",KWhets);
  574.  
  575. #endif
  576.  
  577.    exit(0);
  578.  
  579. }
  580.  
  581. /*******************/
  582. /* Subroutine pa() */
  583. /*******************/
  584.  
  585. pa(e)                /* Exactly as in the Algol 60 version, but we */
  586.                      /* could do away with that 'goto'.            */
  587. double e[4];
  588.  
  589. {
  590.    int j;
  591.  
  592.    j = 0;
  593.      lab:
  594.    e[0] = (  e[0] + e[1] + e[2] - e[3] ) * t;
  595.    e[1] = (  e[0] + e[1] - e[2] + e[3] ) * t;
  596.    e[2] = (  e[0] - e[1] + e[2] + e[3] ) * t;
  597.    e[3] = ( -e[0] + e[1] + e[2] + e[3] ) / t2;
  598.    j ++;
  599.  
  600.    if (j < 6)
  601.       goto lab;
  602. }
  603.  
  604. /************************/
  605. /* Subroutine p3(x,y,z) */
  606. /************************/
  607.  
  608. p3(x, y, z)
  609.  
  610. double x, y, *z;
  611.  
  612. {
  613.    x  = t * (x + y);
  614.    y  = t * (x + y);
  615.    *z = (x + y) /t2;
  616. }
  617.  
  618. /*******************/
  619. /* Subroutine p0() */
  620. /*******************/
  621.  
  622. p0()
  623. {
  624.    e1[j] = e1[k];
  625.    e1[k] = e1[l];
  626.    e1[l] = e1[j];
  627. }
  628.  
  629. /*********************/
  630. /* Subroutine Pout() */
  631. /*********************/
  632.  
  633. #ifdef POUT
  634. Pout(n, j, k, x1, x2, x3, x4)
  635.  
  636. long  n, j, k;
  637. double x1, x2, x3, x4;
  638.  
  639. {
  640.    printf("%5ld %5ld %5ld   %11.3le %11.3le %11.3le %11.3le\n",
  641.       n, j, k, x1, x2, x3, x4);
  642. }
  643. #endif
  644.  
  645. /*************************************/
  646. /* Time Ticks ( 50 * seconds )       */
  647. /*************************************/
  648.  
  649. long timeticks()
  650. {    return clock()/2;
  651. }
  652.  
  653. /*-- End Of Whetstone C Source Code -----------------*/
  654.