Is there any way to check the granularity of gettimeofday() function provided by POSIX?
相关问题
- Multiple sockets for clients to connect to
- Is shmid returned by shmget() unique across proces
- What is the best way to do a search in a large fil
- glDrawElements only draws half a quad
- Index of single bit in long integer (in C) [duplic
Call it in a tight loop, note the difference between the current value and the previous one when it changes. Something like the following:
On my system it seems the granularity is around 2 usec (about 50/50 one or two microseconds, with outliers in the hundreds or thousands that are likely due to task switching).
The current posix way to get the resolution of gettimeofday() is
In older posix versions (not sure when the change happened), the value CLOCKS_PER_SEC was #defined.
Instead of
gettimeofday()
, consider usingclock_gettime()
(specifying theCLOCK_REALTIME
clock). This is also POSIX, and supports aclock_getres()
function to obtain the resolution.