On Tue, Dec 10, 2002 at 10:46:07PM -0000, Smylers wrote:
> > The example above is a classic example of premature optimization.
> > There's nothing which ways the cache would be counter-productive for
> > simple calculations since the caching logic is nearly as simple.
> 
> OK.  There was something on MJD's QOTW recently where using the current
> Perl 5 Memoize module slowed code down -- that gave me the impression
> that caching had the potential.

Applying memoization to really simple calcuations, such as the number of
days in a month, will probably wind up slower than just doing the original
calcuation.  This is also an example of premature optimization. :)

For something as simple as your example, the cost of entering and exiting
the subroutine is probably more expensive than the code to actually do the
work.  In that case you likely want to inline the code which flies off into
a whole other class of optimizations...


> > However, if you *really* want to do partial caching and given that
> > this is an edge case, ...
> 
> It wasn't supposed to be claiming to be a serious function where caching
> would be useful!

I meant that the idea of partial caching is an edge case.


> > I'd say to just do it as two functions
> 
> Yeah, I thought of that (thanks for bothering to write it out) then I
> thought of having the caching be per-C<return> and couldn't work out
> whether it'd be generally useful or not, which is why I asked here, for
> an increased sample size.
> 
> And that increased sample size indicates "not", so I'll forget about it.

I dunno, my motto is "never hurts to put it in a library".


-- 

Michael G. Schwern   <[EMAIL PROTECTED]>    http://www.pobox.com/~schwern/
Perl Quality Assurance      <[EMAIL PROTECTED]>         Kwalitee Is Job One
MERV GRIFFIN!

Reply via email to