DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

difftime(S)


difftime -- computes the difference between time values

Syntax

cc . . . -lc

#include <time.h>

double difftime(time2, time1) time_t time2; time_t time1;

Description

The difftime function computes the difference of time2 - time1.

See the example which follows.

Return value

The difftime function returns the elapsed time in seconds from time1 to time2 as a double-precision number.

See also

ctime(S), mktime(S), nl_cxtime(S), stime(S), time(S)

Standards conformance

difftime is conformant with:

ANSI X3.159-1989 Programming Language -- C .

Example

   #include <time.h>
   

int mark[10000];

main() { time_t start, finish; register int i, loop, n, num, step; printf("This program takes about 3 minutes "); printf("on an AT and 8 on a PC.\n Working...\n"); time(&start);

for (loop = 0; loop < 1000; ++loop) for (num = 0,n = 3; n < 10000; n += 2) if (!mark[n]) { /* printf("%d\n",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), 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. To display the prime numbers, delete the outermost loop and the comment delimiters around the expression printf("%d",n);.
© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003