Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Stopwatch using perl

by Flame (Deacon)
on Jan 29, 2007 at 08:15 UTC ( #597037=note: print w/ replies, xml ) Need Help??


in reply to Stopwatch using perl

This looks like a good start, but I'd like to point out that this program will, on most systems, quickly lose accuracy.

The sleep command, at least as of Perl 5.8.8, is not capable of sleeping at resolutions less than a full second. The Time::HiRes module is recommended as an alternative for those needing better accuracy. In this case, I suspect it is rounding the number down to the nearest whole second, and attempting to sleep for that amount of time. You can check this using the return value from sleep, as it returns the number of seconds actually slept.

Because sleep is returning immediately, the speed of your stopwatch is entirely dependent on how fast the user's computer can print to the console. In my specific case I was able to reach 4 minutes in about 25 seconds.

Because you may not know the speed of the user's computer, it's often wise to change your sleep duration based on how long it took to complete the previous task. In the future, you should try storing the current time before each sleep and using it as a base from which you control your sleeping. (This can get complicated very quickly, depending on your goals.)

Note: It appears that you're just getting started, so don't worry if anything I wrote here was confusing, keep it up and you'll catch on quick.


0x596F752068617665206265656E2068657865642E


Comment on Re: Stopwatch using perl
Re^2: Stopwatch using perl
by ptum (Priest) on Jan 29, 2007 at 16:54 UTC

    This is an excellent template for responding to a new Monk's first post, in several ways:

    • It begins with an encouraging remark
    • It points out a measurable and reproducible flaw
    • It clearly explains the nature of the error
    • It outlines a way to correct or avoid the problem
    • It ends with another encouraging remark

    Throughout the post, the tone was cheerful, polite and avoided patronization. Thanks for raising the bar, Flame!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (11)
As of 2014-12-26 16:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (171 votes), past polls