Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

sleep instead of burning cycles

by Albannach (Prior)
on Jan 05, 2001 at 10:15 UTC ( #50011=note: print w/replies, xml ) Need Help??

in reply to Re: Re: Re: Re: Infinte perl script
in thread Infinte perl script

The point is that while(1){} isn't idle, it's spinning madly behind the scenes, testing 1 as often as possible. In your case you probably have lots of other processes that push your script down to .05%, but I'm just guessing on that. On this old workstation the while(1){} goes up above 90% when not much is happening. Now I'm certainly no expert on process scheduling, but then neither is Win32 ;-).

I've been taught (though it may be deprecated like lots of other things I've learned) that it's just bad manners for a program to basically waste time spinning madly, as you don't know what other apps might want to do with those cycles. If you sleep() you're letting the system decide what to do with those cycles you'd otherwise be wasting. Of course as others have already said, it depends on just how urgent your task is - do you need to act the same millisecond the file is deleted, or is 1/10 of a second fast enough (and don't forget your network latency is probably killing way more response time than the sleep() will).

Maybe if you explain your application a bit more fully the answer will become clearer.

I'd like to be able to assign to an luser

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://50011]
[Lady_Aleena]: shmem, there is ONE song which throws a wrench in the works for both MP3::Info and MP3::Tag.
[shmem]: Lady_Aleena: fix it, or delete it ;-)
[Lady_Aleena]: shmem, I'm not sure how.
[shmem]: well, deleting is done with 'rm' :-P
[shmem]: you can break up the chain MP3::Tag->new($_)- >interpolate("\%S ") and test whether MP3::Tag->new($_) is true
[Lady_Aleena]: shmem, no to deletion.

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2017-04-23 22:12 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (432 votes). Check out past polls.