Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ difftime(3) — AIX PS/2 1.2.1

Media Vault

Software Library

Restoration Projects

Artifacts Sought



DIFFTIME(3,L)               AIX Technical Reference               DIFFTIME(3,L)



-------------------------------------------------------------------------------
difftime



PURPOSE

Computes time difference.

LIBRARY

Standard C Library (libc.a)

SYNTAX

#include <time.h>

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

DESCRIPTION

The difftime macro computes the difference between time2 and time1.  The
difftime macro returns the elapsed time in seconds from time1 to time2 as a
double precision number.  Type time_t is defined in the time.h header file.

EXAMPLE

The following example shows a timing application using difftime.  The example
calculates how long it takes to find the prime numbers from 2 to 10000.

























Processed November 7, 1990       DIFFTIME(3,L)                                1





DIFFTIME(3,L)               AIX Technical Reference               DIFFTIME(3,L)



  #include <time.h>
  #include <stdio.h>
  #define runs 1000
  #define arr_size 10000

  int mark[arr_size];

  main  ()
  {
      time_t start, finish;
      int i, loop, n, num;

      time (&start);
      for  (loop = 0; loop < runs; loop++)
         for  (n = 0; n < arr_size; n++)
            mark [n] = 0;
         for  (num = 0, n = 2; n<arr_size; n++)
            if  (!mark[n]) {
               for  (i = 2*n; i <arr_size; i +=n)
                   mark[i] = -1;
               ++num;
               }
      time (&finish);
      printf ("\nProgram takes %f seconds to find %d primes.\n",
         difftime (finish,start)/runs,num);
  }

Output

The program takes 0.106000 seconds to find 1229 primes.

























Processed November 7, 1990       DIFFTIME(3,L)                                2



Typewritten Software • bear@typewritten.org • Edmonds, WA 98026