Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Reasonably accurate timing

by lhoward (Vicar)
on Jul 23, 2001 at 21:55 UTC ( #99102=note: print w/replies, xml ) Need Help??


in reply to Reasonably accurate timing

How about sleeping until the next polling interval (based on when you started looping) instead of a hardcoded delay? This will account for however long your processing takes (even if the amount of time it takes to process changes). It can be "off" by a fraction of a second, but should correct itself so the drift does not accumulate.
my $t0=time(); while(1){ # do processing # .. # sleep till next polling interval. sleep 60-(time()-$t0)%60; }
Use this concept with Time::HiRes for greater accuracy.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2019-08-25 00:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?