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:
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".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
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |