Let's let Benchmark do the talking...
my( $name, $ascii ); foreach ( qw/ONE TWO THREE FOUR/ ) { $name = ucfirst lc; $ascii = $name; $ascii =~ s/(.)/ord $1/ge; print $ascii; last if $ascii =~ /\d{6,}/; } undef $name; undef $ascii; # or foreach ( qw/ONE TWO THREE FOUR/ ) { my $name = ucfirst lc; my $ascii = $name; $ascii =~ s/(.)/ord $1/ge; print $ascii; last if $ascii =~ /\d{6,}/; }
I decided to do this with a couple of sets of iterations...
Benchmark: timing 100000 iterations of InLoop, OutLoop... InLoop: 4 wallclock secs ( 3.23 usr + 0.00 sys = 3.23 CPU) @ 30 +959.75/s (n=100000) OutLoop: 3 wallclock secs ( 3.59 usr + 0.00 sys = 3.59 CPU) @ 27 +855.15/s (n=100000) Benchmark: timing 1000000 iterations of InLoop, OutLoop... InLoop: 38 wallclock secs (32.36 usr + 0.00 sys = 32.36 CPU) @ 30 +902.35/s (n=1000000) OutLoop: 40 wallclock secs (34.82 usr + 0.00 sys = 34.82 CPU) @ 28 +719.13/s (n=1000000) Benchmark: timing 10000000 iterations of InLoop, OutLoop... InLoop: 372 wallclock secs (322.27 usr + 0.09 sys = 322.36 CPU) @ + 31021.22/s (n=10000000) OutLoop: 411 wallclock secs (347.93 usr + 0.23 sys = 348.16 CPU) @ + 28722.43/s (n=10000000)
Looks pretty close to me, IMHO Initialize _inside_ the loop.

Enjoy!

--
Casey

In reply to Re: Performance question by cwest
in thread Performance question by Anonymous Monk

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.