Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: The Best Infinite Loop

by jdhedden (Deacon)
on Jun 08, 2005 at 12:32 UTC ( #464657=note: print w/replies, xml ) Need Help??


in reply to The Best Infinite Loop

All the differences in timing results presented here (at least for while (), while (1), and for(;;)) are statistically insignificant. The proof for this statement comes from investigating what code is being run in each case. This can be done by using the Perl bytecode compiler (B::Bytecode).

If you execute the following:

perl -MO=Bytecode,-H,-ofor_loop -e 'for (;;) {}' perl -MO=Bytecode,-H,-owhile_loop -e 'while () {}' perl -MO=Bytecode,-H,-owhile1_loop -e 'while (1) {}'
and then diff the resulting files (for_loop, while_loop and while1_loop), you will find that they are all completely identical. This means that all three are exactly equivalent as far as code execution goes. Therefore, which of the three idioms to use is just a matter of personal preference.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://464657]
help
Chatterbox?
NodeReaper tries to shade his eye-sockets with his hands

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2016-12-11 06:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (168 votes). Check out past polls.