Skip to content
Advertisement

Tag: clock

Measuring Elapsed Time Using clock_gettime(CLOCK_MONOTONIC)

I have to elapse the measuring time during multiple threads. I must get an output like this: Firstly, I used gettimeofday but I saw that there are some negative numbers then I made little research and learn that gettimeofday is not reliable to measure elapsed time. Then I decide to use clock_gettime(CLOCK_MONOTONIC). However, there is a problem. When I use

How do the clock function works in operating systems?

I don’t understand how clock function works within an operating system. First the documentation for clock function in www.cplusplus.com is: As far as I understand, the clock function must access directly some register within the CPU that is a counter for CPU cycles. How is this possible? I mean, any register of 32 bits would overflow very soon if it

Measuring execution time with clock in sec in C not working

I’m trying to measure execution time in C using clock() under linux using the following: The output is: The documentation says to divide the clock time by CLOCKS_PER_SEC to get the execution time in sec, but this seems pretty incorrect for a 2sec sleep. What’s the problem? Answer Sleeping takes almost no execution time. The program just has to schedule

Advertisement