http://qs321.pair.com?node_id=883174

in reply to Re: Solution found!
in thread Simple date and time manipulation

What? You're going to compare 16 lines of unrelated code (which contains a nasty loop) to a single line function and call it a benchmark victory? The OP was looking for a quick date time increment. His solution contained this and plenty of other code not directly related to the date time increment. If you're going to benchmark you won't get very far comparing apples to oranges.

By my benchmarking, the OP's "equivalent datetime increment" code is 144 times faster than DateTime and nearly as fast as Date::Calc.

```use strict;
use warnings;

use DateTime;
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);
my (\$mday, \$mon, \$wday, \$yday, \$isdst);
my \$time = time();

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 {
\$time += 3723; # 1 * 60 * 60 + 2 * 60 + 3
(\$sec, \$min, \$hour, \$mday, \$mon, \$year, \$wday, \$yday, \$isdst) =
localtime(\$time);
},
}
);

__END__

Rate   DateTime    tsk1979 Date::Calc
DateTime     2875/s         --       -99%       -99%
tsk1979    431483/s     14910%         --       -18%
Date::Calc 526429/s     18213%        22%         --