Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
difftime
div
Collapse the table of content
Expand the table of content

difftime

Finds the difference between two times.

double difftime( 
   time_t timer1,
   time_t timer0 
);

Parameters

timer1
Ending time.
timer0
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.

Remarks

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

Requirements

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.

Libraries

All versions of the C run-time libraries.

Example

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

Show:
© 2015 Microsoft