Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
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 surveying the Monastery: (10)
As of 2014-08-23 03:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (171 votes), past polls