use strict; use warnings; use Date::Manip; use Date::Calc qw(Add_Delta_DHMS); use Benchmark qw(cmpthese); Date_Init ("TZ=UT"); my @dates = ("2007-04-30 12:50:00", "2007-04-30 11:50:00"); print "Manip result: \n", join "\n", manip (), "\n"; print "Calc result: \n", join "\n", calc (), "\n"; cmpthese (-1, { manip => \&manip, calc => \&calc, }); sub manip { my @results; for (@dates) { my $date = $_; my $hour = (split /:/, $date)[0]; die "Can't find hour" unless $hour =~ /\s(\d{2})$/; if ($1 >= 12){ $date=DateCalc("$date","+24 hours"); ###Takes 2min out of 2:30min. $date=&UnixDate($date,"%Y-%m-%d"); } push @results, $date; } return @results; } sub calc { my @results; for (@dates) { my $date = $_; my $hour = (split /:/, $date)[0]; die "Can't find hour" unless $hour =~ /\s(\d{2})$/; if ($1 >= 12){ my ($year,$month,$day, $hour,$min,$sec) = $date =~ /(\d{4})-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/; ($year,$month,$day, $hour,$min,$sec) = Add_Delta_DHMS ( $year,$month,$day, $hour,$min,$sec, 1, 0, 0, 0 ); $date = "$year-$month-$day $hour:$min:$sec"; } push @results, $date; } return @results; } #### Manip result: 2007-05-01 2007-04-30 11:50:00 Calc result: 2007-5-1 12:50:0 2007-04-30 11:50:00 Rate manip calc manip 662/s -- -99% calc 59112/s 8825% --