home *** CD-ROM | disk | FTP | other *** search
/ PC-Test Pro / PCTESTPRO.iso / benchmrk / tran / entp / tran.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-05  |  5.6 KB  |  123 lines

  1. /*
  2.  * A benchmark for transcendental operations: sin, asin, cos, acos, tan, atan, log, log10.
  3.  * Uses ANSI C features including macro parameter token-pasting.
  4.  * James Day, 100276.3552@compuserve.com 5 Feb 1995
  5.  */
  6.  
  7. #define DEFAULTLOOPS    100000L
  8.  
  9. #include <stdlib.h>
  10. #include <stdio.h>
  11. #include <time.h>
  12. #include <math.h>
  13.  
  14. #define MATHLOOP(Op)                                                       \
  15.    {                                                                       \
  16.    Total = 0.0;                                                            \
  17.    StartClock = clock();                                                   \
  18.    for (Loop = Loops; Loop > 0; Loop--)                                    \
  19.    {                                                                       \
  20.       Total += ##Op(Angle)                                                 \
  21.          + ##Op(Angle+Step1)                                               \
  22.          + ##Op(Angle+Step2)                                               \
  23.          + ##Op(Angle+Step3)                                               \
  24.          + ##Op(Angle+Step4)                                               \
  25.          + ##Op(Angle+Step5)                                               \
  26.          + ##Op(Angle+Step6)                                               \
  27.          + ##Op(Angle+Step7)                                               \
  28.          + ##Op(Angle+Step8)                                               \
  29.          + ##Op(Angle+Step9);                                              \
  30.       Angle += Increment;                                                  \
  31.    }                                                                       \
  32.    BenchTime = (clock() - StartClock);                                     \
  33.    }
  34.  
  35. #define MATHOP(Op)                                                         \
  36.    {                                                                       \
  37.    MATHLOOP(Op);                                                           \
  38.    SecTime = (double)(BenchTime-Overhead) / CLOCKS_PER_SEC;                \
  39.    LoopsPerSec = (long)(Loops * 10 / (BenchTime-Overhead) * CLOCKS_PER_SEC);\
  40.    printf("%10lu in %6.2lf seconds for %10ld " #Op "/s\n",                 \
  41.       Loops*10, SecTime, LoopsPerSec);                                     \
  42.    }
  43.    
  44. #define MATHLOOP2(Op1, Op2)                                                \
  45.    {                                                                       \
  46.    Total = 0.0;                                                            \
  47.    StartClock = clock();                                                   \
  48.    for (Loop = Loops; Loop > 0; Loop--)                                    \
  49.    {                                                                       \
  50.       Total += ##Op1(##Op2(Angle))                                         \
  51.          + ##Op1(##Op2(Angle+Step1))                                       \
  52.          + ##Op1(##Op2(Angle+Step2))                                       \
  53.          + ##Op1(##Op2(Angle+Step3))                                       \
  54.          + ##Op1(##Op2(Angle+Step4))                                       \
  55.          + ##Op1(##Op2(Angle+Step5))                                       \
  56.          + ##Op1(##Op2(Angle+Step6))                                       \
  57.          + ##Op1(##Op2(Angle+Step7))                                       \
  58.          + ##Op1(##Op2(Angle+Step8))                                       \
  59.          + ##Op1(##Op2(Angle+Step9));                                      \
  60.       Angle += Increment;                                                  \
  61.    }                                                                       \
  62.    BenchTime = (clock() - StartClock);                                     \
  63.    }
  64.  
  65. #define MATHOP2(Op1, Op2, BaseTime)                                        \
  66.    {                                                                       \
  67.    MATHLOOP2(Op1, Op2);                                                    \
  68.    SecTime = (double)(BenchTime-Overhead-BaseTime) / CLOCKS_PER_SEC;       \
  69.    LoopsPerSec = (long)(Loops * 10 / (BenchTime-Overhead-BaseTime) * CLOCKS_PER_SEC); \
  70.    printf("%10lu in %6.2lf seconds for %10ld " #Op1 "/s\n",                 \
  71.       Loops*10, SecTime, LoopsPerSec);  \
  72.    }
  73.    
  74. #define DEG_PER_RAD (360/(2*3.14159265))
  75.  
  76. void main(int argc, char *argv[])
  77. {
  78.    unsigned long  Loop, Loops;
  79.    unsigned long  StartClock;
  80.    unsigned long  BenchTime, LoopsPerSec;
  81.    double      Angle, Total, SecTime, Overhead, Increment;
  82.    double      Step1, Step2, Step3, Step4, Step5, Step6, Step7, Step8, Step9;
  83.    double      SinTime, CosTime, TanTime;
  84.  
  85.    if ( argc > 1 )
  86.       Loops = atol(argv[1]);
  87.    else
  88.       {
  89.       printf("Please give the number of loops on the command line.\n"
  90.              "For 486DX-100 I suggest 200000. Choose a number big enough\n"
  91.              "so that the fastest test takes at least ten seconds.\n");
  92.       exit(1);
  93.       }
  94.  
  95.    Increment = 45.0/DEG_PER_RAD/Loops;
  96.    Angle = Increment;
  97.    Step1 = Increment * 0.1;
  98.    Step2 = Increment * 0.2;
  99.    Step3 = Increment * 0.3;
  100.    Step4 = Increment * 0.4;
  101.    Step5 = Increment * 0.5;
  102.    Step6 = Increment * 0.6;
  103.    Step7 = Increment * 0.7;
  104.    Step8 = Increment * 0.8;
  105.    Step9 = Increment * 0.9;
  106.    MATHLOOP();
  107.    Overhead = BenchTime;
  108.  
  109.    MATHOP(sin);
  110.    SinTime = BenchTime;
  111.    MATHOP(cos);
  112.    CosTime = BenchTime;
  113.    MATHOP(tan);
  114.    TanTime = BenchTime;
  115.    MATHOP2(asin, sin, SinTime);
  116.    MATHOP2(acos, cos, CosTime);
  117.    MATHOP2(atan, tan, TanTime);
  118.    
  119.    MATHOP(log);
  120.    MATHOP(log10);
  121. }
  122.  
  123.