note
andreas1234567
<strike>
<blockquote>
It works fast and is tiny.
</blockquote>
I beg to differ. It is both slow and verbose. [mod://DateTime] is <i>10 times faster</i>, and [mod://Date::Calc] is <i>700 times faster</i>!
<readmore>
<c>
use strict;
use warnings;
use DateTime;
use Date::Calc qw (Add_Delta_DHMS);
use Benchmark qw(cmpthese);
my $dt = DateTime->new(
year => 2011,
month => 1,
day => 1,
hour => 0,
minute => 0,
second => 0,
);
my ($year, $month, $day, $hour, $min, $sec) = (2011, 1, 1, 0, 0, 0);
cmpthese(
-1,
{
'DateTime' => sub {
$dt->add(hours => 1, minutes => 2, seconds => 3);
},
'Date::Calc' => sub {
($year, $month, $day, $hour, $min, $sec) =
Add_Delta_DHMS($year, $month, $day, $hour, $min, $sec, 0, 1, 2, 3);
},
'tsk1979' => sub {
my $lat = 23.438;
my $slon = 68.000;
my $elon = 90.000;
my $clon = $slon;
my $incrlon = 0.01;
my $time = time;
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
localtime($time);
my $incrtime = 1;
my $printmon;
my $printyear;
while ($clon < $elon) {
$printmon = $mon + 1;
$printyear = $year + 1900;
$clon = $clon + $incrlon;
$time = $time + $incrtime;
($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
localtime($time);
}
},
}
);
__END__
$ perl -l 883070.pl | tail -5
Rate tsk1979 DateTime Date::Calc
tsk1979 339/s -- -90% -100%
DateTime 3319/s 878% -- -100%
Date::Calc 893673/s 263192% 26830% --
$
</c>
</readmore>
It is a good habit to [mod://Benchmark] your code before making bold claims about its performance.
</strike>
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-321512">
<small>
--<br>
No matter how great and destructive your problems may seem now, remember, you've probably only seen the tip of them. <a href="http://www.despair.com/viewall.html">[1]</a>
</small>
</div></div>
883070
883080