codescracker


c

C difftime()



« Previous Function Next Function »


difftime()

The difftime() function returns the difference, in seconds, between time1 and time2 that is, time2 - time1.

difftime() Syntax

Following is the syntax of the difftime() function :

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

difftime() Example

Following program times the number of seconds that it takes for the empty for loop to go from 0 to 5,000,000 :

#include<time.h>
#include<stdio.h>
#include<conio.h>
void main()
{
	clrscr();
	time_t start, end;
	volatile long unsigned t;
	start = time(NULL);
	for(t=0; t<5000000; t++) ;
	end = time(NULL) ;
	printf("Loop used %f seconds.\n", difftime(end, start));
	getch();
}

« Previous Function Next Function »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test