in reply to Time::HiRes sleep does not always work

Which version of Time::HiRes are you using?

There was a bug in versions < ~1.53 that meant it only used a low-resolution timer. This what later enhanced with the use of a short period, high resolution timer.

However, there were still some circumstances, particularly under the aucpices of the debugger, in which the resolution seemed to fall off quite badly. See In search of a bug in Time::HiRes on Windows..

You mentioned Vista somewhere in one of your replies. Are all the systems running Vista? Maybe there is some incompatibility.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."
  • Comment on Re: Time::HiRes sleep does not always work

Replies are listed 'Best First'.
Re^2: Time::HiRes sleep does not always work
by tone (Novice) on Aug 18, 2008 at 13:04 UTC

    I'm using version 1.9712

    Out of the five systems I tested on only one is running Vista and all the others are on XP.

      Could you post the output from the following on one machine that gives good results and one that gives bad:

      #! perl -slw use strict; use Time::HiRes qw[ gettimeofday time ]; use Win32::API::Prototype; ApiLink( 'kernel32', q[ BOOL QueryPerformanceCounter( LARGE_INTEGER *lpPerformanceCount ) ]) or die $^E; ApiLink( 'kernel32', q[ BOOL QueryPerformanceFrequency( LARGE_INTEGER *lpPerformanceCount +) ]) or die $^E; sub int64_to_NV { my( $lo, $hi ) = unpack 'VV', $_[ 0 ]; return $hi * 2**32 + $lo; } my $frequency = ' ' x 10; QueryPerformanceFrequency( $frequency ) or die $^E; print 'Counter changes ', int64_to_NV( $frequency ), ' times/second'; for ( 1 .. 10 ) { QueryPerformanceCounter( $frequency )or die $^E; print 'QPC: ',int64_to_NV( $frequency ); } printf "GToD: %.8f\n", scalar gettimeofday() for 1 .. 10; printf "Time: %.8f\n", time() for 1 .. 10;

      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

        If I run your script on my machine (bad) I get:

        Counter changes 3579545 times/second QPC: 35752003971 QPC: 35752004170 QPC: 35752004356 QPC: 35752004527 QPC: 35752004695 QPC: 35752004854 QPC: 35752005017 QPC: 35752005169 QPC: 35752005333 QPC: 35752005487 GToD: 1219149309.90625000 GToD: 1219149309.90625000 GToD: 1219149309.90625000 GToD: 1219149309.90625000 GToD: 1219149309.90625000 GToD: 1219149309.90625000 GToD: 1219149309.90625000 GToD: 1219149309.90625000 GToD: 1219149309.90625000 GToD: 1219149309.90625000 Time: 1219149309.90625000 Time: 1219149309.90625000 Time: 1219149309.90625000 Time: 1219149309.90625000 Time: 1219149309.90625000 Time: 1219149309.90625000 Time: 1219149309.90625000 Time: 1219149309.90625000 Time: 1219149309.90625000 Time: 1219149309.90625000

        And here is the output from a "good" machine:

        Counter changes 3579545 times/second QPC: 76031246430 QPC: 76031246657 QPC: 76031246790 QPC: 76031247127 QPC: 76031247273 QPC: 76031247479 QPC: 76031247686 QPC: 76031247838 QPC: 76031247972 QPC: 76031248165 GToD: 1219150762.25000000 GToD: 1219150762.25004410 GToD: 1219150762.25007610 GToD: 1219150762.25010900 GToD: 1219150762.25013900 GToD: 1219150762.25017500 GToD: 1219150762.25020500 GToD: 1219150762.25024100 GToD: 1219150762.25027490 GToD: 1219150762.25030590 Time: 1219150762.25033810 Time: 1219150762.25036690 Time: 1219150762.25039600 Time: 1219150762.25042800 Time: 1219150762.25047900 Time: 1219150762.25053190 Time: 1219150762.25058200 Time: 1219150762.25063110 Time: 1219150762.25066710 Time: 1219150762.25069900