C examples for time.h:clock
function
<ctime> <time.h>
Returns the processor time consumed by the program.
clock_t clock (void);
none
The number of clock ticks elapsed since an epoch.
On failure, the function returns a value of -1.
#include <stdio.h> #include <time.h> #include <math.h> int my (int n) { int i,j;// w w w. j a va 2s .co m int freq=n-1; for (i=2; i<=n; ++i) for (int x=0; x<=100000; ++x) for (j=sqrt(i);j>1;--j) ; return freq; } int main () { clock_t t; int f; t = clock(); printf ("Calculating...\n"); f = my (99999); printf ("done!\n"); t = clock() - t; printf ("It took me %d clicks (%f seconds).\n",t,((float)t)/CLOCKS_PER_SEC); return 0; }