--- Geoffrey Young <[EMAIL PROTECTED]> wrote:
> mod_perl digest
> March 11, 2001 - March 17, 2001
> Recent happenings in the mod_perl world...
> . . .
> mailing list highlights
> . . .
> o There was an OT but interesting thread on whether lexical
> variables are faster than global variables [10]. This
> response in particular may be of interest to those who
> want to know more about perlguts [11]
As one more installment on that thread, I got an email using Benchmark
to test it. It had the my() inside the test function, which was slower
than package globals, but I moved it out and it was faster.
Here's the test synopsis:
===========================
C:\users\default>type tmp.pl
use Benchmark;
my $o; # packagewide deep-bound my() var
sub outMY{
$o = 0; # packagewide deep-bound my() var
$o++ while ($o < 1000);
};
sub inMY{
my $i = 0; # function-internal my() var
$i++ while ($i < 1000);
};
sub gPK{
$g = 0; # package global var
$g++ while ($g < 1000);
};
timethese(5000, { 'External' => \&outMY,
'Internal' => \&inMY,
'Global' => \&gPK } );
C:\users\default>perl -w tmp.pl
Benchmark: timing 5000 iterations of External, Global, Internal...
External: 5 wallclock secs ( 4.96 usr + 0.00 sys = 4.96 CPU)
Global: 5 wallclock secs ( 5.01 usr + 0.00 sys = 5.01 CPU)
Internal: 4 wallclock secs ( 5.07 usr + 0.00 sys = 5.07 CPU)
===================================================================
Notice that a deep-bound my() variable was fastest, while a re-scoped
my() was slowest, the package global being pretty close to halfway
between in actual CPU usage.
Hope that's useful to somebody. =o)
Paul
__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail.
http://personal.mail.yahoo.com/