Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: Unexpected Timing spikes using Time::HiRes

by hossman (Prior)
on Jan 19, 2010 at 08:03 UTC ( #818131=note: print w/replies, xml ) Need Help??

in reply to Unexpected Timing spikes using Time::HiRes

Have you considered checking hte return value of usleep (or sleep) to see how many actual seconds the method slept for, and then compare that with the delta from Time::HiRes::gettimeofday

I suspect that Time::HiRes::gettimeofday is in fact returning the accurate time for your system at the moment you call it, but you are seeing the larger then expected deltas because other things are happening on your system (besides the sleep) in between your calls -- Perl garbage collection, other processes on the same machine, etc....

My first suggestion was to try something like...

time perl -MTime::HiRes -le 'print ((Time::HiRes::gettimeofday())[1]) + for (1..500)'

...where you sanity check the numbers printed out looking for any really odd jumps, and Compare the "real" time reported by your system with the delta between the first/last times printed so see if they concur.

But the compilation/interpreter startup is significant enough to provide missleading info at such a small level of granularity.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://818131]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (2)
As of 2021-10-16 08:07 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (69 votes). Check out past polls.