Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Perl: the Markov chain saw
 
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.


Comment on Re: The Best Infinite Loop
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (14)
As of 2014-04-16 23:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (436 votes), past polls