Possible optimization
Julian Field
MailScanner at ecs.soton.ac.uk
Fri Dec 7 14:14:14 GMT 2007
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Well spotted. I didn't write that bit of code, and obviously didn't
check someone else's contribution closely enough.
Fixed now.
Thanks!
Jules.
Leonardo Helman wrote:
> Hi, yesterday, I came across a chunk of code that I never saw before.
>
>
> --------------------------------------------------------
> sub StartTiming {
> my $this = shift;
> my($varprefix, $usertext) = @_;
>
> my $command = "";
> my $now = time;
>
> $command = '$this->{' . $varprefix . '_starttime} = $now;';
> eval $command;
> }
> ---------------------------------------------------------
>
>
> And the same for StopTiming.
>
> I don't understand why you choose an eval there?
> It's about 20 times slower than doing something like
>
> $$this{$varprefix}{starttime}=$now;
>
> Or something like this if you prefer
>
> $this->{$varprefix . '_starttime'} = $now;
>
>
> I'm very curious about it.
> Why??
>
>
> Here is a benchmark
>
> ---------------------------------------------
> use Benchmark;
> Benchmark::cmpthese(1000000,
> {
> _eval => '_eval',
> _hash => '_hash',
> }
> );
>
> sub _eval {
> my $now = time;
> my $cmd = '$pepe{'.$var.'_start} = $now';
> eval $cmd;
> }
>
> sub _hash{
> $pepe{$var.'_start'} = time;
> }
>
>
> Rate _eval _hash
> _eval 28843/s -- -95%
> _hash 609756/s 2014% --
>
> ---------------------------------------------
>
> Another one
>
> In the cache functions, the uncompress/compress calls should be better
> (cleaner) inside those functions.
>
>
> Saludos
> Leonardo Helman
> PERT Consultores SRL
> Argentina
>
>
>
Jules
- --
Julian Field MEng CITP CEng
www.MailScanner.info
Buy the MailScanner book at www.MailScanner.info/store
Need help customising MailScanner?
Contact me!
Need help fixing or optimising your systems?
Contact me!
Need help getting you started solving new requirements from your boss?
Contact me!
PGP footprint: EE81 D763 3DB0 0BFD E1DC 7222 11F6 5947 1415 B654
-----BEGIN PGP SIGNATURE-----
Version: PGP Desktop 9.7.0 (Build 867)
Comment: (pgp-secured)
Charset: ISO-8859-1
wj8DBQFHWVU2EfZZRxQVtlQRAqgCAKCJUDQPJSWFhwoNavwZEp6c3qEzhQCfe8Lj
8bROsfjaDQx7V1K0V1RTxpQ=
=5Lms
-----END PGP SIGNATURE-----
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
More information about the MailScanner
mailing list