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

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