On Wed, Nov 12, 2008 at 4:10 PM, JC Janos <[EMAIL PROTECTED]> wrote:
> Chas,
>
> On Wed, Nov 12, 2008 at 12:38 PM, Chas. Owens <[EMAIL PROTECTED]> wrote:
>> You may want to also look at Readonly*.
>
> New one for me.  Thanks.
>
>> $WHOIS1 can be modified (not good)
>
> That's an easy point.
>
>> $WHOIS2 cannot be optimized away by the compiler (possible performance 
>> impact)
>
> I have no idea what weight to give that optimization. Is it typically
> large & very useful, or barely noticeable?
>

It's not rally as simple as it sounds: substitution is always being
performed--every occurrence of WHOIS or $WHOIS is being replaced by
your string--the only thing you are using the pragma to control is
whether the substitution happens at compile time or run time. In most
cases, it doesn't make a hill of beans. On my system, for instance,
Benchmark can't find any difference in a simple variable vs. constant
scenario under 1,000,000 iterations; I don't start to see the
improvement until I perform about 10,000,000 substitutions.

Where you really see a performance gain in real life is if you use a
constant value as a part of a condition that contains nothing but
other constant values. In that case the compiler will ignore any code
that cannot be evaluated. This is why you will often see 'use constant
DEBUG = 0' at the beginning of programs. That way debug code switched
as 'if (DEBUG) {...}' is never even compiled unless the program is in
debug mode. In a long, complex program, saving perhaps 1,000+ tests
can be a worthwhile optimization.

For most jobs, though, it makes more sense to think about
functionality, rather than an optimization that might or might not
gain you a fraction of a microsecond. Is there a chance that the
variable might be reset and cause unexpected results? Will
BIG_LETTERS_WITH_UNDERSCORES make your code more readable or easier to
maintain? If so, use constants.

In my experience, though, the convenience of interpolation wins out
99% of the time.

This is particularly true when automating system admin tasks. Once you
launch an external program, any optimizations to your Perl code will
be insignificant--statistically and otherwise--compared to the runtime
of the external system call.

HTH,

-- jay
--------------------------------------------------
This email and attachment(s): [  ] blogable; [ x ] ask first; [  ]
private and confidential

daggerquill [at] gmail [dot] com
http://www.tuaw.com  http://www.downloadsquad.com  http://www.engatiki.org

values of β will give rise to dom!

Reply via email to