Is it possible to calculate the difference between two separate time registers for less than one second using the computer's clock? For example, between 12h00m00s000ms and 12h00m00s050ms.
Is it possible to calculate the difference between two separate time registers for less than one second using the computer's clock? For example, between 12h00m00s000ms and 12h00m00s050ms.
Take a look at this: clock_getres, clock_gettime, clock_settime And here: link
int clock_getres(clockid_t clk_id, struct timespec *res);
The
clock_getres()
function finds the resolution (precision) of the specified% clock, and, ifclk_id
is notres
, stores the result in structNULL
pointed to bytimespec
. Clock resolution depends on the implementation and can not be configured by a particular process. If the time value pointed by the argumentres
oftp
is not a multiple ofclock_settime()
, then it is truncated to a multiple ofres
.int clock_gettime(clockid_t clk_id, struct timespec *tp); int clock_settime(clockid_t clk_id, const struct timespec *tp);
The
res
andclock_gettime()
functions retrieve and assign the time of the% specified% clock.