Accurate timing in C code



What can I use for accurately measuring elapsed time in C code? I'm
looking for round about millisecond accuracy. I've written some code to
wait for vsyncs using OpenGL, but while glXGetRefreshRateSGI reports a
consistent 59Hz, measuring the time between two syncs with gettimeofday
results in a period corresponding to anything up to 88Hz, although it
does seem to usually give 59.8802.

I tried clock(), but that doesn't return anything useful.

Most video players seem to use /dev/rtc but I can't find useful
documentation about it. The kernel docs suggest that the way it's used
is that you program it with the frequency you want it to generate
interrupts (requiring root access for >64Hz, so that's a problem for a
start). Wouldn't that affect the whole machine? What if two applications
want to use it at the same time, at different frequencies? And the clock
can be disturbed by its being kept in sync with external sources etc.

--
The address in the Reply-To is genuine and should not be edited.
See <http://www.realh.co.uk/contact.html> for more reliable contact addresses.
.



Relevant Pages

  • Re: WTF with my computer clock?
    ... Here in Jerusalem, we don't receive the signals of WWVB, or the German ... or how often it syncs. ... ethernet port on one end for NTP sync and a 60kHz transmitter to sync a ... clock on the other. ...
    (sci.electronics.repair)
  • Re: Time not holding in Parallels Desktop
    ... | it syncs with Apple'stimeservers. ... would keep its software clock as well as the hardware clock in UTC ... while Windowskeepsits clock in local ...
    (comp.sys.mac.misc)
  • Re: Going insane - Xilinx VGA controller...
    ... and a 25MHz dot clock) with a 32MBit SDRAM frame buffer (using two Xilinx block RAMs as alternate line buffers). ... It is a 4-layer PCB with a 25MHz master clock. ... and then things go dead for 800ms -- no syncs, ...
    (comp.arch.fpga)
  • Re: Accurate timing in C code
    ... looking for round about millisecond accuracy. ... Leaving out specialized stuff like real time clocks and video card ... That has a similar problem to clock(). ...
    (uk.comp.os.linux)
  • Re: System Clock Apparently Gaining One Second Every 30 Minutes [Telecom]
    ... There may have been a telephone based service where you got clock pulses ... from the atomic clock (I think there is only one in the country that is ... access to the =voice= time there, in addition to the WWV voice channel ... millisecond accuracy. ...
    (comp.dcom.telecom)