Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

somewhat related.. (OT)

by archen (Pilgrim)
on Mar 17, 2002 at 03:27 UTC ( #152265=note: print w/replies, xml ) Need Help??

in reply to Do-nothing loops

Actually a friend of mine in college made an egg timer (in VB) that did something similar. It went something like
while now <> time show time on main form end while
(or however the hell VB syntax works). It was sort of interesting that his entire machine would literally slow to a crawl while it was running, so as other people have been saying - yes these sorts of loops really will eat all your CPU cycles. {I think a few months later he was enlightened by the VB Timer function} And I'm sure the admin of the server you put it on wouldn't be too happy either ;)

Replies are listed 'Best First'.
Re: somewhat related.. (OT)
by Wassercrats on Mar 17, 2002 at 04:31 UTC
    Yes, but if it was up to me, I'd eliminate sleep and make Perl smart enough to know when a loop does nothing but waste time so it will work as sleep and waste no resources. Unless sleep has other uses.
      How would Perl know how long a given no-op loop is supposed to run?

      For example, very old games, like from the early '80's, were written using CPU timers (which are your do-nothing loops). They were built for a computer whose speed was within certain parameters. When you improved your computer, those games got so fast it was ridiculous. (Try playing Pong where the ball moves faster across your screen than your computer can track a keypress!)

      sleep is built so that it receives a certain amount of time. It passes that as a message to the operating system who knows how long a second is. Perl should not make those determinations. That's what operating systems are for. :-)

      So, use the right tool for the right situation. If you need sleep, then use sleep. If you need a no-op loop, then use a no-op loop. (There are uses for them other than spinning your computer's wheels.)

      We are the carpenters and bricklayers of the Information Age.

      Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

        I "learned" programming on a TRS-80 (I failed the class). Then I taught myself on a Commodore and used those for-next loops to waste time, which is why I figured their used in Perl. I admit that sleep saves a bit of time, but both sleep and do-nothing loops don't work for all the things I used to use them for. As far as I know, you can't write a game like you described in Perl becuase time delays don't work when you want them to work. A time delay for displaying a message before something loads works, but the amount of time isn't very important in that case, and if computers triple in speed in five years, it wouldn't be a big deal.

        But if there is really a use for empty loops in perl besides wasting time, then I guess Perl wouldn't know when to sleepize the empty loop and when not to, so sleep would be needed. If it's just a matter of testing processing speed, something can be put within the loop to prevent Perl from sleepizing it, and sleep can be put to sleep.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://152265]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2018-05-23 00:08 GMT
Find Nodes?
    Voting Booth?