Name
difftime - Computes the difference between time values.
Syntax
#include <time.h>
double difftime(time2, time1)
time_t time2;
time_t time1;
Description
The difftime function computes the difference of time2 -
time1.
Return Value
The difftime function returns the elapsed time in seconds
from time1 to time2 as a double-precision number.
See Also
time(S)
Example
#include <time.h>
int mark[10000];
main() {
time_t start, finish;
register int i, loop, n, num, step;
time(&start);
for (loop = 0; loop < 1000; ++loop)
for (num = 0,n = 3; n < 10000; n += 2)
if (!mark[n])
{
step = 2*n;
for (i = 3*n; i < 10000; i += step)
mark[i] = -1;
++num;
}
time(&finish);
/* Prints average of 1000 loops through "sieve": */
printf("\nProgram takes %f seconds to find %d
primes.\n", difftime(finish, start)/1000, num); }
Output:
Program takes 0.482000 seconds to find 1228 primes.
This program calculates the amount of time needed to find
the prime numbers between 3 and 10,000.
(printed 6/18/89)