Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
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 studying the Monastery: (9)
As of 2015-07-05 18:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (67 votes), past polls