/* * $ gcc -ocpu_time__clock_t cpu_time__clock_t.c; ./cpu_time__clock_t */ #include #include #include int main() { volatile int i; clock_t time_start, time_end; double cpu_time_used; #ifdef sysconf fprintf(stdout, "Number of clock ticks per sec ``sysconf(_SC_CLK_TCK)'': %ld\n",sysconf(_SC_CLK_TCK)); #endif fprintf(stdout, "Number of clock ticks per second measured by the clock function ``CLOCKS_PER_SEC'': %ld\n", CLOCKS_PER_SEC); time_start = clock(); for (i=0; i<100000000; i++) ; time_end = clock(); cpu_time_used = ((double) (time_end - time_start)) / CLOCKS_PER_SEC; fprintf(stdout, "CPU time used for %ld iterations: %f\n", i, cpu_time_used); return 0; }