Thank you for the patch, but it introduces dependencies on things like
clock_t ot CLOCKS_PER_SEC which I'm not sure how portable and problem-free
they are, and just now I have not the time to assess such potential problems
for a minor detail like this.
I see.
I found it in libc manual, CPU time inquiry:
https://www.gnu.org/software/libc/manual/html_node/CPU-Time.html
There is also processor time inquiry (https://www.gnu.org/software/libc/manual/html_node/Processor-Time.html) but it uses clock_t s well.
As forportability, the oldest compilers I have tested were: it is defined in gcc-4.1/glibc-2.5, clang-3.2 (uses libc), mingw since at least mingw-gcc-3.4.2. Arm is using newer compiler/s. I don't have other OSes to test.
If someone wants to test it I attached test file in C.
Regards
/* * $ gcc -ocpu_time__clock_t cpu_time__clock_t.c; ./cpu_time__clock_t */ #include <stdio.h> #include <time.h> #include <unistd.h>
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;
}
