difftime

Calculates the difference between two calendar times (function or macro)

Local Servers:nonblocking
Remote Servers:N/A
Classification:ANSI
Service:Mathematical Computation

Syntax

  #include <time.h>  
   
  double difftime  (  
     time_t   time1,   
     time_t   time0);
  

Parameters

time1
(IN) Specifies the calendar time to compare to time0.
time0
(IN) Specifies the calendar time to compare to time1

Return Values

difftime returns the difference between the two times in seconds as a double type.

Remarks

The difftime function or macro calculates the difference between time1 and time0 ( time1 - time0).

See Also

asctime, asctime_r, clock, ctime, ctime_r, gmtime, gmtime_r, localtime, localtime_r, mktime, strftime, time

Example

  #include <stdio.h>  
  #include <time.h>  
   
  void time_test ()  
  {  
     extern compute ();  
     time_t start_time, end_time;  
     start_time = time (NULL);  
     compute();  
     end_time = time (0);  
     printf("Elapsed time: %u seconds", (unsigned int)
             difftime(end_time, start_time));  
  }
  

produces the following:

  Elapsed time: 14 seconds