difftime64() — Compute Time Difference

Format

#include <time.h>
double difftime64(time64_t time2, time64_t time1);

Language Level

ILE C Extension

Threadsafe

Yes

Description

The difftime64() function computes the difference in seconds between time2 and time1.

Return Value

The difftime64() function returns the elapsed time in seconds from time1 to time2 as a double precision number. Type time64_t is defined in <time.h>.

Example

This example shows a timing application that uses difftime64(). The example calculates how long, on average, it takes to find the prime numbers from 2 to 10 000.
#include <time.h>
#include <stdio.h>
 
#define RUNS 1000
#define SIZE 10000
 
int mark[SIZE];
 
int main(void)
{
   time64_t start, finish;
   int i, loop, n, num;
 
   time64(&start);
 
   /*  This loop finds the prime numbers between 2 and SIZE   */
   for (loop = 0; loop < RUNS; ++loop)
      {
      for (n = 0; n < SIZE; ++n)
         mark [n] = 0;
      /*  This loops marks all the composite numbers with -1  */
      for (num = 0, n = 2; n < SIZE; ++n)
         if ( ! mark[n])
         {
            for (i = 2 * n; i < SIZE; i += n)
                mark[i] = -1;
            ++num;
         }
      }
   time64(&finish);
   printf("Program takes an average of %f seconds "
                  "to find %d primes.\n",
                   difftime64(finish,start)/RUNS, num);
}
 
/********************  Output should be similar:  *****************
 
The program takes an average of 0.106000 seconds to find 1229 primes.
*/

Related Information