Dave Rolsky asked:
The first question to answer is what are people doing with these
objects?

Geoffrey Young wrote:
in our case, creating many, many, many of them.  more than you can possibly
imagine.  think one object with a few dozen "time" representations held
within it, then a few thousand of those floating around at any given second.
all within a mod_perl process where memory, not lookups, was the main
(perceived) concern.


I have written a module I tentatively call DateTime::Diet that helps with this. I use DateTime in all sort of projects including hooks in Class::DBI where many many table records all become DateTime objects, even if I don't need the column that represents a DateTime.


DateTime::Diet (attached) is a simple wrapper around DateTime that handles simple new(), set() and get methods. If you ask it for something it can't handle by itself, it reblesses your object into full DateTime and then calls the method on the DateTime object.

It does no parameter checking of its own, as it's designed to work with data that's already been checked in other places.

I've not extensively tested it, but want comments before I go any further. 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.

Cheers!
Rick Measham


These tests compare DateTime::Diet to DateTime for object creation, plus simple accessors and mutators

Benchmark: timing 50000 iterations of       DateTime, DateTime::Diet...
DateTime: 32 wallclock secs (28.33 usr + 0.01 sys = 28.34 CPU) @ 1764.29/s (n=50000) DateTime::Diet: 3 wallclock secs ( 1.76 usr + 0.00 sys = 1.76 CPU) @ 28409.09/s (n=50000)


These tests compare DateTime::Diet to DateTime for the same things, but then call a non-diet function causing the object to become a full blown DateTime object.

Benchmark: timing 10000 iterations of       DateTime, DateTime::Diet...
DateTime: 6 wallclock secs ( 5.97 usr + 0.00 sys = 5.97 CPU) @ 1675.04/s (n=10000) DateTime::Diet: 4 wallclock secs ( 3.07 usr + 0.00 sys = 3.07 CPU) @ 3257.33/s (n=10000)

Attachment: datetime.test.pl
Description: Perl program

Reply via email to