Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Expand Minimize


Finds the difference between two times.

double difftime( 
   time_t timer1,
   time_t timer0 


Ending time.
Beginning time.

Return Value

difftime returns the elapsed time in seconds, from timer0 to timer1. The value returned is a double-precision, floating-point number.


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


Routine Required header Compatibility
difftime <time.h> ANSI, Win 98, Win Me, Win NT, Win 2000, Win XP

For additional compatibility information, see Compatibility in the Introduction.


All versions of the C run-time libraries.


// 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.

See Also

Floating-Point Support Routines | Time Management Routines | time | Run-Time Routines and .NET Framework Equivalents

© 2015 Microsoft