As a rule, I'm blissfully ignorant of technical details surrounding windows implementations of perl, but now there's something I need to know, and I'm hoping there's a monk out there who has experience with certain details...

I have a perl script using Time::HiRes (in particular its "time" function) to write a log file of elapsed times (in fractional seconds) for key strokes, and this is being done while an audio recording process is going on. (Each key stroke brings up a new phrase on the display, and a person reads the phrase aloud.)

So, each keyboard input event relates to (immediately precedes) a spoken utterance in the audio file, and the plan is that the time stamps in the log file will match up with audio time offsets, so that the key-stroke times will identify the locations of the utterances in the recording.

The problem is that the values returned by Time::HiRes on this windows/cygwin setup appear to be moving along faster than "real" elapsed time, as marked by the audio data. For example:

Since the keyboard clicks are audible in the audio, and the log file includes the text for each phrase being displayed, I can tell that the log file times and audio locations match pretty well at the beginning of a session, but for an utterance that occurs at 300.0 sec from the start of the audio file, the corresponding log file time stamp shows 302.5 (roughly) -- that is, Time::HiRes is gaining about half a second for every minute of elapsed time.

The man page for the module contains this little gem:

... in Win32 (and derived platforms like Cygwin and MinGW) the Time::HiRes::time() may temporarily drift off from the system clock (and the original time()) by up to 0.5 seconds. Time::HiRes will notice this eventually and recalibrate.

Has anyone been bothered by this "feature"? Can anyone elaborate on what sort of behavior I should expect (e.g. sudden/unpredictable "re-alignments" in the middle of a session log file, or a consistent pattern of resets at specific intervals)? Is there a sensible solution or workaround for getting accurate timing data?


In reply to Time::HiRes (un)reliability in Windows/Cygwin ?? by graff

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.