We had some date routines in Slash that were just way too slow.  When I 
started working on this code it used Date::Manip, and I never bothered 
to see how it compared speedwise to the modules I had always used, 
Date::Parse and Date::Format.  So I did a benchmark this morning on my 
PowerBook G3/400 (Mac OS 9.1).

#!/usr/bin/perl -w
use strict;
BEGIN { $ENV{TZ} = "GMT" }
use Date::Manip qw(UnixDate DateCalc);
use Date::Parse;
use Date::Format;
use Benchmark;
use vars qw($date $off_set $format $dm $dp);

$date = "2000-01-25 17:36:15";
$off_set = "-14400";
$format = "%A %B %d, @%H:%M";

timethese(1000, {
   manip => <<'EOT',
$dm = DateCalc($date, "$off_set SECONDS");
$dm = UnixDate($dm, $format);
EOT
   parse => <<'EOT',
$dp = str2time($date) + $off_set;
$dp = time2str($format, $dp);
EOT
});

print $dm, "\n";
print $dp, "\n";

__END__

Benchmark: timing 1000 iterations of manip, parse...
     manip: 16 secs (16.63 usr  0.00 sys = 16.63 cpu)
     parse:  2 secs ( 1.45 usr  0.00 sys =  1.45 cpu)
Tuesday January 25, @13:36
Tuesday January 25, @13:36

Yikes!

I went up to 10,000 iterations, and tried on an Intel Linux box, with 
similar results: for the above operations, Date::Manip is about 15x 
slower than Date::Parse + Date::Format.

Enjoy,

-- 
Chris Nandor                      [EMAIL PROTECTED]    http://pudge.net/
Open Source Development Network    [EMAIL PROTECTED]     http://osdn.com/

Reply via email to