Syntax
#include <time.h> clock_t clock(void);Description
If the value of the processor time is not available or cannot be represented, clock returns the value (clock_t)-1.
To measure the time spent in a program, call clock at the start of the program, and subtract its return value from the value returned by subsequent calls to clock.
This example prints the time elapsed since the program was invoked.
#include <time.h> #include <stdio.h> double time1,time2,timedif; /* use doubles to show small values */ int i; int main(void) { time1 = (double)clock(); /* get initial time in seconds */ time1 = time1/CLOCKS_PER_SEC; /* use some CPU time */ for (i = 0; i < 5000000; i++) { int j; j = i; } time2 = (double)clock(); /* call clock a second time */ time2 = time2/CLOCKS_PER_SEC; timedif = time2-time1; printf("The elapsed time is %f seconds\n", timedif); return 0; /**************************************************************************** The output should be similar to: The elapsed time is 0.969000 seconds ****************************************************************************/ }Related Information