Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

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?

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (9)
As of 2015-10-14 00:20 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (318 votes), past polls