[Omaha.pm] benchmark and md5sum

Andy Lester andy at petdance.com
Sun May 14 11:57:06 PDT 2006


On May 14, 2006, at 10:44 AM, Dave M wrote:

> I often use the same md5 subroutine in all my scripts for various
> reasons. Recently I saw another way to read it in, and it appears to
> be faster:

The #1 rule of benchmarking is to pull out as much irrelevant stuff  
as you can.  For instance, the check for -d $file should be done  
outside of the benchmarked functions.  It's the same in both  
functions, and skew your results.  What if that check for the  
directory turns out to be 90% of the runtime in both cases?

Other than that, I don't see anything else to pull out, though.

You might want to try this:

                 my $slurp  = do { local $/; <FH> };
                 my $md5sum = Digest::MD5::md5_hex($slurp);

as

                 local $/;
                 my $md5sum = Digest::MD5::md5_hex(<FH>);

This removes the assignment of a local variable which you're then  
going to copy.

xoa



--
Andy Lester => andy at petdance.com => www.petdance.com => AIM:petdance



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/omaha-pm/attachments/20060514/9f2b25fe/attachment.html 


More information about the Omaha-pm mailing list