in reply to Solution found!
in thread Simple date and time manipulation
It works fast and is tiny.I beg to differ. It is both slow and verbose. DateTime is 10 times faster, and Date::Calc is 700 times faster!
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% -- $
--
No matter how great and destructive your problems may seem now, remember, you've probably only seen the tip of them. [1]
No matter how great and destructive your problems may seem now, remember, you've probably only seen the tip of them. [1]
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Solution found!
by ruzam (Curate) on Jan 19, 2011 at 17:35 UTC |
In Section
Seekers of Perl Wisdom