/* time_of_day just print day/month/year hour:minute:second */ /* also get CPU time as double precision floating point */ /* #define CLOCKS_PER_SEC (1000000) */ /* for SIGPRO */ #include /* in past might be */ #include #include int main() { struct tm *today ; time_t my_time; char ascii_string[100]; double cpu_time; int i, j; cpu_time = (double)clock() / (double)CLOCKS_PER_SEC; printf(" %g CPU time \n", cpu_time); my_time = time(&my_time); today = localtime(&my_time); strcpy(ascii_string, asctime(today)); printf(" %d / %d / %d \n", today->tm_mday, today->tm_mon+1, /* fix */ today->tm_year+1900); printf(" %d : %d : %d \n", today->tm_hour, today->tm_min, today->tm_sec); printf(" ascii string %s \n", ascii_string); /* waste time to get non zero CPU time */ cpu_time = 1.0; for(j=0; j<1000; j++) { for(i=0; i<10000; i++) { cpu_time = 3.2*cpu_time-1.001*(2.99*cpu_time-0.001/cpu_time); } } printf("waste time %g \n", cpu_time); cpu_time = (double)clock() / (double)CLOCKS_PER_SEC; printf(" %g CPU time \n", cpu_time); return 0; } /* output: 0 CPU time 22 / 4 / 96 2 : 59 : 33 ascii string Mon Apr 22 02:59:33 1996 waste time 0.035529 5.82 CPU time */