Recently i had a choice between two modules, Date::Manip, and Date::Pcalc (a perl version of Date::Calc). I originally went with Manip, but someone pointed out that manip was supposed to be slower, so i went out and benchmarked them, and came up with:
use Benchmark;
timethese(10_000,{
'Pcalc' => sub {
require Pcalc;
my $date=20020428182540;
my @date;
push @date,substr($date,0,4,'');
for my $i(0..int (length $date)/2){push @date,substr($date,0,2,'')
+;}
pop @date;
my @diff=reverse Date::Pcalc::Delta_DHMS(@date,Date::Pcalc::Today_
+and_Now());
return "[$diff[0]s:$diff[1]m:$diff[2]h:$diff[3]d]";},
'manip' => sub{
require Manip;
$main::TZ='EST';
my $d1=Date::Manip::ParseDate(20020428182540);
my $d2=Date::Manip::ParseDate('today');
my $err;
my $delta=Date::Manip::DateCalc($d2,$d1,\$err,1);
my $first=substr($delta,0,1,'');
my @d=reverse split /:/,$delta;
return ($first eq '-')?
"[$d[0]s:$d[1]m:$d[2]h] $d[3]d-$d[5]m-$d[6]y":
"This was posted in the future. Bummer. Odd aint it?";}
})
Which gave me the following results:
Benchmark: timing 10000 iterations of Pcalc, manip...
Pcalc: 2 wallclock secs ( 1.98 usr + 0.00 sys = 1.98 CPU)
@ 5050.51/s (n=10000)
manip: 49 wallclock secs (49.10 usr + 0.00 sys = 49.10 CPU)
@ 203.67/s (n=10000)
Now, even realizing that manip is supposed to be slower, Thats a rather extreme difference. Anyone else have useful module benchmarks to share in the context of choosing one over the other?