in reply to Perl and common subexpressions

Manually perform subexpression elimination in tight loops as often as you practically can. It can make quite a bit of difference in a CPU-bound script. (Remember -- 25% is the difference between an hour and 45 minutes.)
Please be very, very carefully with drawing conclusions. You have performed a benchmark, with one specific set of data, using a specific versions of Perl, for a specific version of a certain OS, running on a specific set of hardware. All you have proven so far is that with this particular combination of data, OS, perl version and hardware, you have a 25% gain. For someone else, using a different OS, a different CPU, or a different version of Perl, the numbers might be different.

Note also that a 25% improvement in an very, very simple loop seldomly translates to 25% improvement in the overall program. If only for the fact you'll typically do more in the loop.

Replies are listed 'Best First'.
Re^2: Perl and common subexpressions
by Stevie-O (Friar) on Dec 23, 2004 at 15:13 UTC
    This is very true.

    That is, by the way, why I qualified my statement with 'CPU-bound'. When the bulk of your program involves I/O, the overhead from array, hash, and stash lookups becomes negligible -- even for pipes, because they involve context switches to the process on the other end of the pipe.

    --Stevie-O
    $"=$,,$_=q>|\p4<6 8p<M/_|<('=> .q>.<4-KI<l|2$<6%s!<qn#F<>;$, .=pack'N*',"@{[unpack'C*',$_] }"for split/</;$_=$,,y[A-Z a-z] {}cd;print lc