in reply to Time::Hires Granularity

I just ran this code on my laptop for 170k prints per second. Note that printing takes a bit of time:

use Time::HiRes 'time'; my $end_secs = 5; my $elapsed = 0; my $start = time(); while ($elapsed < $end_secs) { $elapsed = time() - $start; print "$elapsed\n"; }

Update: Sorry, I forgot why I was posting. I'm using Linux and slightly different code, both of which may make a difference. If my code runs the same as your code on your machine, it's likely a Windows thing, as tye has already pointed out.

Replies are listed 'Best First'.
Re: Re: Time::Hires Granularity
by pseudosocrates (Sexton) on Dec 04, 2003 at 05:53 UTC
    Thanks for the reply, maybe I was unclear...
    The issue is not the number of prints. As I said I am getting about 700 prints of the same time, and then the next set of lines is time+0.06
    I am confused as to why the routine can loop 700 times without updating the 'time' variable. Is is that the system is only capable of receiving a request for the time information every .06 seconds? I was hoping that the increment would be smaller (1/100th of a second would be fine). Is this a Windows issue, or, less likely, a code problem; if so, are there any sensible workarounds that anyone could suggest.
    Cheers :-)
      As I said I am getting about 700 prints of the same time, and then the next set of lines is time+0.06
      Actually, it should be closer to 0.055.

      Windows' internal click gets updated 18 times a second, or once every 55ms, via a timer interrupt. The API call GetTickCount() exhibits the same behaviour as you describe here. The docs for this API call mention:

      It is limited to the resolution of the system timer.
      So yes, even though I haven't seen any evidence that the two phenomenons are indeed related, their symptoms are so strikingly alike, that I'm quite convinced they share the same origin. So yes, it's a Windows Thing™.

      Update: I don't mean to say it cannot be fixed/patched, only that this is behaviour you'll typically only see in Windows, for this particular case.

        So yes, it's a Windows Thingâ„¢.

        I think that is a little unfair. With the appropriate patches to Time::HiRes, it's resolution could be improved markedly. Leastwise for elapsed timing if not easily for absolute timing.


        Examine what is said, not who speaks.
        "Efficiency is intelligent laziness." -David Dunham
        "Think for yourself!" - Abigail
        Hooray!
        Wanted!

Re: Re: Time::Hires Granularity
by Anonymous Monk on Dec 04, 2003 at 05:42 UTC
    And?