RE: from_epoch for DateTime::LazyInit?

2006-04-24 Thread Garrett, Philip \(MAN-Corporate\)
> -Original Message-
> From: Rick Measham [mailto:[EMAIL PROTECTED] 
> Sent: Sunday, April 23, 2006 8:13 PM
> To: Garrett, Philip (MAN-Corporate)
> Cc: datetime@perl.org
> Subject: Re: from_epoch for DateTime::LazyInit?
>
>
> P.S. if you want to run benchmarking on the overloading, and it shows
>  that it doesn't increase load or creation time(span) of DT:LI
>  objects I'm willing to reconsider, but I'm a bit loathe :)

There is no discernible difference with the overloading. Not sure what
you mean by "load" time but if it's module load time you're worried
about, DateTime::LazyInit requires DateTime which requires overload --
this doesn't load any modules that weren't already loaded.

With overload:

$ ./bench.pl 10
Benchmark: timing 10 iterations of create_and_inflate,
create_only...
create_and_inflate: 42 wallclock secs (41.91 usr +  0.09 sys = 42.00
CPU) @ 2380.95/s (n=10)
create_only:  2 wallclock secs ( 1.46 usr +  0.01 sys =  1.47 CPU) @
68027.21/s (n=10)

Without overload:

$ ./bench.pl 10
Benchmark: timing 10 iterations of create_and_inflate,
create_only...
create_and_inflate: 43 wallclock secs (43.16 usr +  0.11 sys = 43.27
CPU) @ 2311.07/s (n=10)
create_only:  2 wallclock secs ( 1.45 usr +  0.03 sys =  1.48 CPU) @
67567.57/s (n=10)

I ran this several times.  Each time the results were slightly
different.  Sometimes the code with overloads was faster than the code
without, and vice versa.  The time averaged at about the same (68k/s)
with both versions.

The script:

#!/usr/bin/env perl
use strict;
use warnings;
use Benchmark qw(timethese);
use DateTime::LazyInit;


timethese( @ARGV, {
create_only => '
my $dtli = DateTime::LazyInit->from_epoch( epoch => time );
',
create_and_inflate => '
my $dtli = DateTime::LazyInit->from_epoch( epoch => time );
$dtli->__inflate("epoch");
',
});



Re: from_epoch for DateTime::LazyInit?

2006-04-23 Thread Dave Rolsky

On Mon, 24 Apr 2006, Rick Measham wrote:

P.S. if you want to run benchmarking on the overloading, and it shows that it 
doesn't increase load or creation time(span) of DT:LI objects I'm willing to 
reconsider, but I'm a bit loathe :)


I'd be very surprised if declaring overloading had any impact on object 
construction. It only comes into play at runtime when you use an 
overloaded object in an operation that could be overloaded.



-dave

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


Re: from_epoch for DateTime::LazyInit?

2006-04-23 Thread Rick Measham

Garrett, Philip (MAN-Corporate) wrote:

I'm just trying to make the DT::LI object act like a DT.  Isn't that the idea?


The idea is to allow quick creation of DT objects .. mainly for the 
purpose of creating thousands of DT object that lazily inflate to 
full-blown DateTime objects. It would be good to transparently inflate 
everything, but I'm not going to do that at the expense of adding overloads.


To help with this, the next release will have inflate() rather than 
__inflate() in order to allow deliberate inflation without feeling like 
you're messing with internals.


I think it will also allow you to add a Class name to inflate() so that 
you can use your subclassing ..


print ref $dtLI;
# DateTime::LazyInit;

$dtLI->inflate('yourClass');

print ref $dtLI;
# yourClass

Cheers!
Rick Measham

P.S. if you want to run benchmarking on the overloading, and it shows 
that it doesn't increase load or creation time(span) of DT:LI objects 
I'm willing to reconsider, but I'm a bit loathe :)





RE: from_epoch for DateTime::LazyInit?

2006-04-23 Thread Garrett, Philip \(MAN-Corporate\)
> --
> From: Rick Measham [mailto:[EMAIL PROTECTED]
> Sent: Sun 4/23/2006 6:11 PM
> To: Garrett, Philip (MAN-Corporate)
> Cc: datetime@perl.org
> Subject: Re: from_epoch for DateTime::LazyInit?
> 
> Garrett, Philip (MAN-Corporate) wrote:
> > I also had trouble with the lazyinit module not supporting overloaded
> > operators, e.g. $dt1 > $dt2.
> >
> > To fix, I added this to the main LazyInit package. Using the method
> > names as strings didn't work -- I guess overload doesn't like AUTOLOAD.
> >
> > use overload ( 'fallback' => 1,
> >'<=>' => sub { shift->_compare_overload(@_) },
> 
> We're really getting way beyond the scope of DT::LI here .. it's
> supposed to be completely simple front-end to creating unvalidated
> DateTime objects.
>
> If you want to do comparisons, use the real functions rather than the
> overloads, or create full DateTime objects.
 
I'm just trying to make the DT::LI object act like a DT.  Isn't that the idea?
 
Philip
 


Re: from_epoch for DateTime::LazyInit?

2006-04-23 Thread Rick Measham

Garrett, Philip (MAN-Corporate) wrote:

I also had trouble with the lazyinit module not supporting overloaded
operators, e.g. $dt1 > $dt2.

To fix, I added this to the main LazyInit package. Using the method
names as strings didn't work -- I guess overload doesn't like AUTOLOAD.

use overload ( 'fallback' => 1,
   '<=>' => sub { shift->_compare_overload(@_) },


We're really getting way beyond the scope of DT::LI here .. it's 
supposed to be completely simple front-end to creating unvalidated 
DateTime objects.


If you want to do comparisons, use the real functions rather than the 
overloads, or create full DateTime objects.


Cheers!
Rick Measham



RE: from_epoch for DateTime::LazyInit?

2006-04-23 Thread Garrett, Philip \(MAN-Corporate\)
> -Original Message-
> From: Garrett, Philip (MAN-Corporate)
> Sent: Saturday, April 22, 2006 10:51 PM
> To: datetime@perl.org
> Subject: RE: from_epoch for DateTime::LazyInit?
> 
> > -Original Message-
> > From: Garrett, Philip (MAN-Corporate)
> > Sent: Saturday, April 22, 2006 6:56 PM
> > To: datetime@perl.org
> > Subject: RE: from_epoch for DateTime::LazyInit?
> > 
> > > -Original Message-
> > > From: Rick Measham [mailto:[EMAIL PROTECTED]
> > > Sent: Wednesday, April 05, 2006 8:16 PM
> > > To: Garrett, Philip (MAN-Corporate)
> > > Cc: datetime@perl.org
> > > Subject: Re: from_epoch for DateTime::LazyInit?
> > > 
> > > Garrett, Philip (MAN-Corporate) wrote:
> > > > Are there any plans to add a from_epoch constructor for
> > > > DateTime::LazyInit? The module looks really useful for me, but
> > > > since I create almost all my DateTime objects from epoch times,
I
> > > > can't use it.
> > >
> > > No plans at all .. but if you provide a patch that looks like it
> > > will fit within the goals of LI, I'll have a look.
> >
> > Wanna give this a try? I added support for all the other
constructors
> > as well.

I also had trouble with the lazyinit module not supporting overloaded
operators, e.g. $dt1 > $dt2.

To fix, I added this to the main LazyInit package. Using the method
names as strings didn't work -- I guess overload doesn't like AUTOLOAD.

use overload ( 'fallback' => 1,
   '<=>' => sub { shift->_compare_overload(@_) },
   'cmp' => sub { shift->_compare_overload(@_) },
   '""'  => sub { shift->_stringify(@_) },
   '-'   => sub { shift->_subtract_overload(@_) },
   '+'   => sub { shift->_add_overload(@_) },
 );

Philip


RE: from_epoch for DateTime::LazyInit?

2006-04-23 Thread Garrett, Philip \(MAN-Corporate\)
> -Original Message-
> From: Garrett, Philip (MAN-Corporate)
[mailto:[EMAIL PROTECTED] 
> Sent: Sunday, April 23, 2006 12:00 AM
> To: datetime@perl.org
> Subject: RE: from_epoch for DateTime::LazyInit?
> 
> > -Original Message-
> > From: Rick Measham [mailto:[EMAIL PROTECTED]
> > Sent: Saturday, April 22, 2006 11:16 PM
> > To: Garrett, Philip (MAN-Corporate)
> > Cc: datetime@perl.org
> > Subject: Re: from_epoch for DateTime::LazyInit?
[snip]
> > > I also added an overloadable class method __datetime_class() so
> > > that if you want to use a subclass of DateTime (as I do) then you
> > > can.
> >
> > I'm not sure I want to do this .. we don't do this sort of thing in
> > any other DateTime module (afaik) so until we work out if/how we
> > want to do it then I'm a little loathe to include it.
> >
> > Unless Dave and the rest of the DateTime team want to chime in, I'd
> > just suggest you overload the whole __inflate() routine.
>
> That's fine too. However, the underscores in front of the method name
> indicate to me that it's "extremely private." Making the DateTime
> class name overloadable is both easier for users (since they don't
> have to implement all the innards of __inflate) and more easily
> documented.

Maybe I should have tested this better before I opened my big mouth. It
doesn't even work because of the constructor strategy.

Phili


RE: from_epoch for DateTime::LazyInit?

2006-04-22 Thread Garrett, Philip \(MAN-Corporate\)
> -Original Message-
> From: Rick Measham [mailto:[EMAIL PROTECTED] 
> Sent: Saturday, April 22, 2006 11:16 PM
> To: Garrett, Philip (MAN-Corporate)
> Cc: datetime@perl.org
> Subject: Re: from_epoch for DateTime::LazyInit?
> 
> Garrett, Philip (MAN-Corporate) wrote:
> > Whoops, the patch I sent earlier is botched. This one should be
better.
> > One thing I forgot was to update the POD -- I'll try to get that
later.
> 
> Thanks Philip,
> I'd already noticed it wasn't working and fixed it .. :)

Doh!  Sorry.

> > I also added an overloadable class method __datetime_class() so that

> > if you want to use a subclass of DateTime (as I do) then you can.
> 
> I'm not sure I want to do this .. we don't do this sort of thing in
> any other DateTime module (afaik) so until we work out if/how we want
> to do it then I'm a little loathe to include it.
>
> Unless Dave and the rest of the DateTime team want to chime in, I'd
> just suggest you overload the whole __inflate() routine.

That's fine too. However, the underscores in front of the method name
indicate to me that it's "extremely private." Making the DateTime class
name overloadable is both easier for users (since they don't have to
implement all the innards of __inflate) and more easily documented.

My $0.02.

Thanks,
Philip


Re: from_epoch for DateTime::LazyInit?

2006-04-22 Thread Rick Measham

Garrett, Philip (MAN-Corporate) wrote:

Whoops, the patch I sent earlier is botched. This one should be better.
One thing I forgot was to update the POD -- I'll try to get that later.


Thanks Philip,
I'd already noticed it wasn't working and fixed it .. :)


I also added an overloadable class method __datetime_class() so that if
you want to use a subclass of DateTime (as I do) then you can.


I'm not sure I want to do this .. we don't do this sort of thing in any 
other DateTime module (afaik) so until we work out if/how we want to do 
it then I'm a little loathe to include it.


Unless Dave and the rest of the DateTime team want to chime in, I'd just 
suggest you overload the whole __inflate() routine.


Cheers!
Rick Measham



RE: from_epoch for DateTime::LazyInit?

2006-04-22 Thread Garrett, Philip \(MAN-Corporate\)
> -Original Message-
> From: Garrett, Philip (MAN-Corporate)
[mailto:[EMAIL PROTECTED] 
> Sent: Saturday, April 22, 2006 6:56 PM
> To: datetime@perl.org
> Subject: RE: from_epoch for DateTime::LazyInit?
> 
> > -Original Message-
> > From: Rick Measham [mailto:[EMAIL PROTECTED]
> > Sent: Wednesday, April 05, 2006 8:16 PM
> > To: Garrett, Philip (MAN-Corporate)
> > Cc: datetime@perl.org
> > Subject: Re: from_epoch for DateTime::LazyInit?
> > 
> > Garrett, Philip (MAN-Corporate) wrote:
> > > Are there any plans to add a from_epoch constructor for 
> > > DateTime::LazyInit? The module looks really useful for me, but
since 
> > > I create almost all my DateTime objects from epoch times, I can't 
> > > use it.
> >
> > No plans at all .. but if you provide a patch that looks like it
> > will fit within the goals of LI, I'll have a look.
>
> Wanna give this a try? I added support for all the other constructors
> as well.

Whoops, the patch I sent earlier is botched. This one should be better.
One thing I forgot was to update the POD -- I'll try to get that later.

I also added an overloadable class method __datetime_class() so that if
you want to use a subclass of DateTime (as I do) then you can.

Philip



DateTime-LazyInit.patch
Description: DateTime-LazyInit.patch


RE: from_epoch for DateTime::LazyInit?

2006-04-22 Thread Garrett, Philip \(MAN-Corporate\)

> -Original Message-
> From: Rick Measham [mailto:[EMAIL PROTECTED] 
> Sent: Wednesday, April 05, 2006 8:16 PM
> To: Garrett, Philip (MAN-Corporate)
> Cc: datetime@perl.org
> Subject: Re: from_epoch for DateTime::LazyInit?
> 
> Garrett, Philip (MAN-Corporate) wrote:
> > Are there any plans to add a from_epoch constructor for
> > DateTime::LazyInit? The module looks really useful for me, but since
> > I create almost all my DateTime objects from epoch times, I can't
> > use it.
>
> No plans at all .. but if you provide a patch that looks like it will
> fit within the goals of LI, I'll have a look.

Wanna give this a try? I added support for all the other
constructors as well.

Thanks,
Philip



DateTime-LazyInit.patch
Description: DateTime-LazyInit.patch


Re: from_epoch for DateTime::LazyInit?

2006-04-05 Thread Rick Measham

Garrett, Philip (MAN-Corporate) wrote:

Are there any plans to add a from_epoch constructor for
DateTime::LazyInit?  The module looks really useful for me, but since I
create almost all my DateTime objects from epoch times, I can't use it.


No plans at all .. but if you provide a patch that looks like it will 
fit within the goals of LI, I'll have a look.


Cheers!
Rick Measham


from_epoch for DateTime::LazyInit?

2006-04-05 Thread Garrett, Philip \(MAN-Corporate\)
Hi list.

 

Are there any plans to add a from_epoch constructor for
DateTime::LazyInit?  The module looks really useful for me, but since I
create almost all my DateTime objects from epoch times, I can't use it.

 

Philip