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 >
Wrap
C/C++ Source or Header
|
1985-08-29
|
763b
|
31 lines
#include <stdio.h>
#include "cputim.h"
#define LOOPCNT 100000
main()
{
double time0, timediv, timeadd;
long a, b = 255, c = 255, i;
cputim(); /* time the timing harness */
for (i = 1; i <= LOOPCNT; ++i)
a = b;
time0 = cputim() * (1e6 / CLOCK_TICKS_PER_SECOND);
cputim(); /* time the divide operator */
for (i = 1; i <= LOOPCNT; ++i)
a = b / c;
timediv = cputim() * (1e6 / CLOCK_TICKS_PER_SECOND);
cputim(); /* time the addition operator */
for (i = 1; i <= LOOPCNT; ++i)
a = b + c;
timeadd = cputim() * (1e6 / CLOCK_TICKS_PER_SECOND);
printf("long divides require %.1f microseconds \n",
(timediv - time0)/LOOPCNT);
printf("long additions require %.1f microseconds \n",
(timeadd - time0)/LOOPCNT);
}