On Wed, 6 Jul 2005, Rick Measham wrote:

I've included the output of the attached script below. I was surprised to note that even after the rebless was included in the tests, the Diet version was still *much* quicker.

I'm not sure what you mean. It's much quicker for operations that occur before the rebless. If you were to keep using that object for further operations, the speed increase given from calling one "diet" method would fade into background noise.

For example:

  timethese(10000,
            {
             '      DateTime' =>
             sub { my $dt = new DateTime( year => 2004 );
                   my $day = $dt->day;
                   $dt->set_minute(22);
                   $dt->datetime;
                   for ( qw( year month hour day minute second nanosecond ) ) {
                       my $foo = $dt->$_();
                   }
                   $dt->set_minute(30);
                   for ( qw( year month hour day minute second nanosecond ) ) {
                       my $foo = $dt->$_();
                   }
               },
          'DateTime::Diet' =>
             sub { my $dt = new DateTime::Diet( year => 2004 );
                   my $day = $dt->day;
                   $dt->set_minute(22);
                   $dt->datetime;
                   for ( qw( year month hour day minute second nanosecond ) ) {
                       my $foo = $dt->$_();
                   }
                   $dt->set_minute(30);
                   for ( qw( year month hour day minute second nanosecond ) ) {
                       my $foo = $dt->$_();
                   }
               },
  });

I get these results:

  Benchmark: timing 10000 iterations of       DateTime, DateTime::Diet...
        DateTime:  8 wallclock secs ( 8.26 usr +  0.00 sys =  8.26 CPU) @ 
1210.65/s (n=10000)
  DateTime::Diet:  7 wallclock secs ( 6.44 usr +  0.00 sys =  6.44 CPU) @ 
1552.80/s (n=10000)

So it still has an impact, but it's starting to become less and less significant.

But this might be useful for cases where people have to create lots of objects, they don't care about time zones, and they rarely have to use the "advanced" DT.pm methods (math, time zones, etc).

I suspect people would want to be able to use this in conjunction with a parser like DT::Format::MySQL or something, where they know the data in the DB represents real datetimes.

That's not currently possible, but it could be added to the generic DT::Format::* API spec.


-dave

/*===================================================
VegGuide.Org                        www.BookIRead.com
Your guide to all that's veg.       My book blog
===================================================*/

Reply via email to