Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ difftime(S) — System V/386 Software Development System 3.2.2b

Media Vault

Software Library

Restoration Projects

Artifacts Sought



     DIFFTIME(S)               UNIX System V               DIFFTIME(S)



     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;
                  printf("This program will take 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);.


     Standards Conformance
          difftime is conformant with:
          ANSI X3.159-198X C Language Draft Standard, May 13, 1988.





                                             (printed 6/20/89)



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