home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 161_01 / harness3.c < prev    next >
C/C++ Source or Header  |  1985-08-29  |  811b  |  32 lines

  1. /* harness3 - time long divide and long add */
  2. #include <stdio.h>
  3. #include "cputim.h"
  4.  
  5. #define LOOPCNT 100000
  6.  
  7. main()
  8.     {
  9.     double time0, timediv, timeadd;
  10.     long a, b = 255, c = 255, i;
  11.  
  12.     cputim();  /* time the timing harness */
  13.     for (i = 1; i <= LOOPCNT; ++i)
  14.         a = b;
  15.     time0 = cputim() * (1e6 / CLOCK_TICKS_PER_SECOND);
  16.  
  17.     cputim();  /* time the divide operator */
  18.     for (i = 1; i <= LOOPCNT; ++i)
  19.         a = b / c;
  20.     timediv = cputim() * (1e6 / CLOCK_TICKS_PER_SECOND);
  21.  
  22.     cputim();  /* time the addition operator */
  23.     for (i = 1; i <= LOOPCNT; ++i)
  24.         a = b + c;
  25.     timeadd = cputim() * (1e6 / CLOCK_TICKS_PER_SECOND);
  26.  
  27.     printf("long divides require %.1f microseconds \n",
  28.         (timediv - time0)/LOOPCNT);
  29.     printf("long additions require %.1f microseconds \n",
  30.         (timeadd - time0)/LOOPCNT);
  31.     }
  32.