On Fri, Sep 15, 2000 at 09:00:33AM -0500, Tim Ayers wrote: > I benchmarked calculating 170!. I did it with and without caching, > i.e. in Michael's and my solution I reset the cache before calling > factorial(170). I'm really impressed at the speed of Michael's > solution. How in the world is it so fast? I noticed that your two benchmarks were nearly the same, regardless of caching, which ain't right. For some reason, using a string to benchmark (ie. schwern => '%factorial = (); schwern(170)') wasn't clearing the caches. If you did it in a subroutine, (schwern => sub { %factorial = (); schwern(170) }) then things work. I never anticipated anyone clearing Tie::Math's cache, so the thing seems to fall apart if you do so "Out of memory during "large" request for 134221824 bytes". I'll have to figure out why that is. > So as always, my solution is mediocre, but my initial reaction to > Michael's answer was, "If I wanted to write code like that, I'd learn > Prolog." ;-) It was actually inspired in a discusion with my old boss about memoization. He mentioned that in Mathematica you can just write out a function, and it would figure it out including caching. At the time I was looking for an excuse to use lvalue subroutines, so tada! -- Michael G Schwern http://www.pobox.com/~schwern/ schwern@pobox.com Just Another Stupid Consultant Perl6 Kwalitee Ashuranse <GuRuThuG> make a channel called Perl, and infest it with joking and fun....it doesnt make alot of sense. ==== Want to unsubscribe from Fun With Perl? Well, if you insist... ==== Send email to <fwp-request@technofile.org> with message _body_ ==== unsubscribe