home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Washington_1988 / DevCon88.3 / IEEE / src / bench / float.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-27  |  3.0 KB  |  133 lines

  1. /*----------------------- Float C Source Starts Here ---------------------*/
  2.  
  3.  
  4. /*******************************************************/
  5. /*                        Float.c                      */
  6. /* Tests speed at which a system does double precision */
  7. /* floating-point multiply and divide instructions. A  */
  8. /* total of 140,000 Double Precision FP operations.    */
  9. /*                                                     */
  10. /*                         Flt.c                       */
  11. /* Tests speed at which a system does double precision */
  12. /* floating-point add, subtract, multiply, and divide  */
  13. /* instructions.  Roughly 1 million DP FP operations.  */
  14. /*******************************************************/
  15.  
  16. #include <math.h>
  17. #include <stdio.h>
  18.  
  19.  
  20. /*******************/
  21. /*     Float.c     */
  22. /*******************/
  23. #define CONST1 3.1415970E0
  24. #define CONST2 1.7839032E4
  25. #define COUNT  10000
  26.  
  27. main()
  28. {
  29.    double a,b,c;
  30.    long i,j,loops;
  31.    long  starttime,stoptime,benchtime;
  32.    long  nulltime,timeticks();            /* timeticks() is specific to */
  33.                                           /* the Amiga. Replace with    */
  34.                                           /* with your system timer     */
  35.    starttime = timeticks();
  36.    stoptime  = timeticks();
  37.    nulltime  = stoptime - starttime;
  38.  
  39.    printf("\n   Float Benchmark\n");
  40.    printf("   Start %d Loops \n",COUNT);
  41.  
  42.    starttime = timeticks();               /* Start timer. */
  43.  
  44.    a = CONST1;
  45.    b = CONST2;
  46.  
  47.    for(i=0;i<COUNT;++i)
  48.       {
  49.       c = a*b;
  50.       c = c/a;
  51.  
  52.       c = a*b;
  53.       c = c/a;
  54.  
  55.       c = a*b;
  56.       c = c/a;
  57.  
  58.       c = a*b;
  59.       c = c/a;
  60.  
  61.       c = a*b;
  62.       c = c/a;
  63.  
  64.       c = a*b;
  65.       c = c/a;
  66.  
  67.       c = a*b;
  68.       c = c/a;
  69.       }
  70.  
  71.    stoptime  = timeticks();               /* Stop timing. */
  72.  
  73.    benchtime = stoptime - starttime - nulltime;
  74.    a = (double)benchtime/50.0;
  75.  
  76.    printf("   Done.\n");
  77.    printf("   Benchtime (sec) = %lf\n\n",a);
  78.  
  79. /***************/
  80. /*    Flt.c    */
  81. /***************/
  82.  
  83.    loops = 256000;
  84.    printf("   FLT Benchmark\n");
  85.    printf("   Start %ld loops.\n",loops);
  86.  
  87.    starttime = timeticks();               /* Start timing */
  88.  
  89.    for( i=1 ; i<=loops ; i++ )
  90.    {
  91.    j = loops - i;
  92.    a = (double)i;
  93.    b = (double)j;
  94.    c = b / a;
  95.    a = b - c;
  96.    b = c * a;
  97.    c = b + a;
  98.    }
  99.  
  100.    a = c + b;
  101.  
  102.    stoptime  = timeticks();               /* Stop timing. */
  103.  
  104.    benchtime = stoptime - starttime - nulltime;
  105.    a = (double)benchtime/50.0;
  106.  
  107.    printf("   Done.\n");
  108.    printf("   Benchtime (sec) = %lf\n\n",a);
  109.  
  110. }
  111.  
  112.  
  113. /*******************************************************/
  114. /* Function Returns ticks ( 50 per sec) since midnight.*/
  115. /* Amiga specific, Replace with your own routine.      */
  116. /*******************************************************/
  117.  
  118. long  timeticks()
  119. {
  120.    struct   ds {
  121.       long  days;
  122.       long  minutes;
  123.       long  ticks;
  124.    }  ds;
  125.    DateStamp(&ds);
  126.    return(ds.ticks + (ds.minutes * 60 * 50));
  127. }
  128.  
  129. /*----------------------- End of C Program Code --------------------------*/
  130.  
  131.  
  132.  
  133.