I didn't like that article a bit. If you want to improve the performance of your Perl program Perl Monks is a much better resource. If I recall correct there has been nodes about this before. (Update: or see When Perl is not quite fast enough as Corion pointed out.)

By the way, in this example, an even quicker way of producing a string that repeats the alphabet 999,999 times would be to use:
$concat = 999999 x 'abcdefghijklmnopqrstuvwxyz';

It must be rather embarrassing to make this obvious mistake that no one that writes an article about Perl should make.

A bit further down the article I read "Better still, in a simple calculation like this one or for any straightforward loop work, use map:", and then the author uses map BLOCK in void context instead of a for loop. Overlooking style issues it's still not a very good advice to me:

use Benchmark 'cmpthese'; use strict; use warnings; my @stuff = 1 .. 20000; cmpthese(-3, { 'for EXPR' => sub { my $a = 0; ++$a for @stuff; }, 'for BLOCK' => sub { my $a = 0; for (@stuff) { ++$a } }, 'map BLOCK' => sub { my $a = 0; map { ++$a } @stuff; }, 'map EXPR' => sub { my $a = 0; map ++$a, @stuff; }, }); __END__ Rate map BLOCK map EXPR for BLOCK for EXPR map BLOCK 50.4/s -- -4% -44% -49% map EXPR 52.3/s 4% -- -42% -47% for BLOCK 89.9/s 78% 72% -- -9% for EXPR 98.6/s 96% 89% 10% -- This is perl, v5.8.0 built for MSWin32-x86-multi-thread
From there on, I didn't give the article much credibility nor read it too closely. I did notice some either ignorant or poorly expressed statements, but I won't even bother elaborating. Update: Although it raised some valid points it didn't elaborate when necessary -- I find it far too "simple".

ihb

See perltoc if you don't know which perldoc to read!
Read argumentation in its context!


In reply to Re: Optimize Perl by ihb
in thread Optimize Perl 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.