Export (0) Print
Expand All
div
eof
Expand Minimize
1 out of 1 rated this helpful - Rate this topic

difftime, _difftime32, _difftime64 

Finds the difference between two times.


double difftime( 
   time_t timer1,
   time_t timer0 
);
double _difftime32( 
      __time32_t timer1,
   __time32_t timer0 
);
double _difftime64( 
   __time64_t timer1,
   __time64_t timer0 
);

Parameters

timer1

Ending time.

timer0

Beginning time.

difftime returns the elapsed time in seconds, from timer0 to timer1. The value returned is a double precision floating-point number. The return value may be 0, indicating an error.

The difftime function computes the difference between the two supplied time values timer0 and timer1.

The time value supplied must fit within the range of time_t. In Visual C++ 2005, time_t is a 64-bit value. Thus, the end of the range was extended from 03:14:07 January 19, 2038 to 23:59:59, December 31, 3000. The lower range of time_t is still midnight, January 1, 1970.

In Visual C++ 2005, difftime is an inline function that evaluates to either _difftime32 or _difftime64 depending on whether _USE_32BIT_TIME_T is defined. _difftime32 and _difftime64 can be used directly to force the use of a particular size of the time type.

These functions validate their parameters. If either of the parameters is zero or negative, the invalid parameter handler is invoked, as described in Parameter Validation. If execution is allowed to continue, these functions return 0 and set errno to EINVAL.

Routine Required header Compatibility

difftime

<time.h>

ANSI, Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003

_difftime32

<time.h>

Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003

_difftime64

<time.h>

Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003

For additional compatibility information, see Compatibility in the Introduction.

// crt_difftime.c
// This program calculates the amount of time
// needed to do a floating-point multiply 500 million times.
//

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main( void )
{
   time_t   start, finish;
   long loop;
   double   result, elapsed_time;

   printf( "Multiplying 2 floating point numbers 500 million times...\n" );
   
   time( &start );
   for( loop = 0; loop < 500000000; loop++ )
      result = 3.63 * 5.27; 
   time( &finish );

   elapsed_time = difftime( finish, start );
   printf( "\nProgram takes %6.0f seconds.\n", elapsed_time );
}

Sample Output

Multiplying 2 floating point numbers 500 million times...

Program takes      5 seconds.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.