#include #include #include extern clock_t clock(void); int main(int argc, char *argv[]) { /* clock_t is something integral (i.e. int, unsigned int ). */ clock_t t1,t2; /* Note that t below is double; if t was clock_t then time would be truncated */ double t; int i; double j; j=0.0; t=0.0; t1=clock(); /* Time something here */ for (i=0;i<=10000000;i++){ j = j+ (double)(i*i); } t2=clock(); if (t2 == ((clock_t) -1) ) { printf("Something wrong is going on! Processor time not available \n"); } t = (t2-t1)/((double)CLOCKS_PER_SEC); printf("%d %f %f \n",i-1,j,(double)t); }