Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sysconf(_SC_CLK_TCK) vs. CLOCKS_PER_SEC

I was wondering what is the difference between the return value of the aforementioned constants.

sysconf(_SC_CLK_TCK) returns 100
CLOCKS_PER_SEC returns 1,000,000

So, suppose that I have this:

...
start = clock();
// Process starts here 
/* does something */
// Process ends here
end = clock();
double time = ((double) end-start)/CLOCK_PER_SEC; // this would return in seconds
...

How do I calculate the amount of ticks used by the process, instead of the time? Do I use time used against sysconf(_SC_CLK_TCK) or CLOCK_PER_SEC?

I am trying to understand the usage of those.

like image 913
thedarkguy Avatar asked Oct 29 '22 19:10

thedarkguy


1 Answers

As per the documentation, clock() returns time in resolution of CLOCKS_PER_SEC.

Other time functions return values with resolution in ticks. sysconf(_SC_CLK_TCK) provides the number of ticks per second. One such time function is times().

like image 144
jxh Avatar answered Nov 15 '22 07:11

jxh