Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
go ahead... be a heretic
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

I looked at those benchmarks and said, "Well, those all took the same amount of time." Then I read the conclusions drawn and frowned. The numbers are way too close together to determine that any of these are faster than the other. In fact, I'd be surprised if the first two don't compile to the exact same parse tree.

Compare my benchmarks:

#!/usr/bin/perl -w use strict; use Benchmark; timethese( 1000, { '0while' => sub { $_ = 0; while (1) { $_++; last if ($_ == 10000 +); } }, '0for' => sub { $_ = 0; for (;;) { $_++; last if ($_ == 10000 +); } }, '0block' => sub { $_ = 0; { $_++; redo if ($_ < 10000) +; } }, '1while' => sub { $_ = 0; while (1) { $_++; last if ($_ == 10000 +); } }, '1for' => sub { $_ = 0; for (;;) { $_++; last if ($_ == 10000 +); } }, '1block' => sub { $_ = 0; { $_++; redo if ($_ < 10000) +; } }, }); __END__ Benchmark: timing 1000 iterations of 0block, 0for, 0while, 1block, 1for, 1while... 0block: 7 wallclock secs ( 6.81 CPU) @ 146.84/s 0for: 7 wallclock secs ( 6.98 CPU) @ 143.27/s 0while: 7 wallclock secs ( 6.70 CPU) @ 149.25/s 1block: 6 wallclock secs ( 6.37 CPU) @ 156.99/s 1for: 6 wallclock secs ( 6.26 CPU) @ 159.74/s 1while: 6 wallclock secs ( 6.32 CPU) @ 158.23/s
Note that the first time for(;;) is the slowest and the second time it is the fastest.

I'm sticking with while(1) since I think it looks nicer.

        - tye (but my friends call me "Tye")

In reply to (tye)RE: The Best Infinite Loop by tye
in thread The Best Infinite Loop by zdog

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others meditating upon the Monastery: (10)
    As of 2014-04-23 23:20 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      April first is:







      Results (557 votes), past polls