You see? it's converted to for (;;) because it's more effecient. We can't benchmark the difference because of this optimization...

Hmm, im sorry but this is inconclusive to me. The output of B::Deparse is not necessarily exactly what is happening under the hood (as I said to kanji above). Now you may be correct that perl optimizes for(;;) and while(1) into the same construct, but nothing ive seen posted here shows what that construct is.

BTW a benchmark of while(1) versus for(;;) is as follows:

Benchmark: timing 1000000 iterations of for(;;), while(1)... for(;;): 71 wallclock secs (71.66 usr + 0.00 sys = 71.66 CPU) @ 13 +955.57/s (n=1000000) while(1): 71 wallclock secs (71.67 usr + 0.00 sys = 71.67 CPU) @ 13 +952.45/s (n=1000000) Rate while(1) for(;;) while(1) 13952/s -- -0% for(;;) 13956/s 0% --
I agree this suggests they optimize down to the same thing..

:-)

Yves / DeMerphq
---
Writing a good benchmark isnt as easy as it might look.


In reply to Re: Re: Re: Re: Re: Re: infinite loop on while (@array) by demerphq
in thread infinite loop on while (@array) by jrasillo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.