in reply to In search of a bug in Time::HiRes on Windows.

(n = 10,000) >perl !.pl 1.2 1118813755.17075 1118813755.18637 (n = 100,000) >perl !.pl 1.2 1118813761.18637 1118813761.202 1118813761.21762 1118813761.23325 1118813761.24887 1118813761.2645 >perl -v This is perl, v5.8.0 built for MSWin32-x86-multi-thread (with 1 registered patch, see perl -V for more detail) Binary build 806 provided by ActiveState Corp. http://www.ActiveState. +com Built 00:45:44 Mar 31 2003 ...

I had to use ppm to install Time::HiRes for 5.6.1. I had to reduce the loop to 10, down from 100,000:

(n=10) >perl !.pl 1.63 1118814102.57754 1118814102.57761 1118814102.57767 1118814102.57773 1118814102.57793 1118814102.57799 1118814102.57805 1118814102.57812 1118814102.57818 1118814102.57824 >perl -v This is perl, v5.6.1 built for MSWin32-x86-multi-thread (with 1 registered patch, see perl -V for more detail) Copyright 1987-2001, Larry Wall Binary build 635 provided by ActiveState Corp. http://www.ActiveState. +com Built 15:34:21 Feb 4 2003 ...

It seems 5.6.1's Time::HiRes has a much better resolution than 5.8.0's. Is that the bug for which you are searching? My 5.8.0 results seem different from everyone else's results.

Replies are listed 'Best First'.
Re^2: In search of a bug in Time::HiRes on Windows.
by BrowserUk (Patriarch) on Jun 15, 2005 at 06:26 UTC

    Warning: Long & complicated story! (With a request at the end)

    It seems 5.6.1 has a much better resolution than 5.8.0. Is that the bug for which you are searching?

    It's not quite that simple. Time::HiRes v1.2 is a very old version I think which could explain your results. Later versions (circa. >= 1.53 ) have code which uses a high resolution performance counter to enhance the low resolution of the GetSystemTimeAsFileTime() api.

    However, under some circumstances, the use of the high res timer doesn't seems to work correctly. For example:

    On my system, doing it this way the resolution is around 70/80 uSeconds:

    P:\test>perl -MTime::HiRes=time -wle"print time for 1 .. 10" 1118814859.12534 1118814859.12551 1118814859.12558 1118814859.12566 1118814859.12573 1118814859.1258 1118814859.12587 1118814859.12594 1118814859.12602 1118814859.12609

    but in the debugger, it suddenly becomes 31.25 milliseconds:

    P:\test>perl -MTime::HiRes=time -de1 perldb: Must not source insecure rcfile ./perldb.ini. You or the superuser must be the owner, and it must not be writable by anyone but its owner. Loading DB routines from perl5db.pl version 1.25 Editor support available. Enter h or `h h' for help, or `perldoc perldebug' for more help. main::(-e:1): 1 DB<1> print time . $/ for 1 .. 20;; 1118815107.6875 1118815107.6875 1118815107.6875 1118815107.6875 1118815107.6875 1118815107.6875 1118815107.6875 1118815107.6875 1118815107.6875 1118815107.6875 1118815107.6875 1118815107.6875 1118815107.71875 1118815107.71875 1118815107.71875 1118815107.71875 1118815107.71875 1118815107.71875 1118815107.71875 1118815107.73438 DB<2>

    which is strange enough, but it gets stranger. I saw spurperl's comment in Re^2: Microseconds in Per regarding Time::HiRes resolution on Win32 and it reminded me of a similar effect I pursued a while ago after reading Unique filenames with Time::HiRes which lead to Re^4: Perl -de1 weirdness..

    I was on a different machine/version of the OS back then, and when I tried to trackdown the problem, I couldn't reproduce it outside the debugger. Whilst I did raise a mention on p5p, a bug in a timer that only occurs inside the debugger isn't really critical.

    However, and this is where it gets really strange, the other day when I read spurperl's comment, I ran the above test, and I was getting the 31.25 millsecond resolution outside of the debugger! Last night I decided to try and track it down again, and I ran some code using Win32::API to access the performance counter directly. Twiddled around a bit and then tried the test above again, and suddenly, the I was getting the 70/80 microsecond resolution outside of the debugger. I didn't install anything new.

    Puzzled, I eventually tried rebooting to see what if any difference that made and it made none at all. I now have the high resolution timer outside of the debugger and nothing I have tried reverts me to the low res situation outside of the debugger.

    Great you might say, but this is where I was on my old machine. I had the low-res timer always. Played with calling the performance counter, suddenly got the high res results and could find no way to revert outside of the debugger!

    My feeling is that Windows is caching some state somewhere and that the calls inside Time::HiRes.xs are not triggering the enablement of the performance counter on their own. But once the performance counter has been enabled, Time::HiRes is able to use it from that point on. How/why that would be so I cannot imagine at this stage.

    So, what I need is someone who has Time::HiRes v 1.53 or greater that is getting low-res results. I am not sure whether the Perl version is relevant or not yet. PodMaster showed that high resolution results are possible on every build.

    If I can find someone with T::H >1.53 getting low-res results, then I will ask then to run the piece of Win32::API code that appeared to make the difference on my machine and see if it has the same enabling effect for them.

    Is there any chance of you upgrading to T::H > 1.53 in your 5.8.x install?

    If you cannot find a PPM, I could always email you the files from here.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.