in reply to Re: Operations with Extremely Large Numbers (BigApprox)
in thread Operations with Extremely Large Numbers

Thanks for the interesting insight tye. Going along those lines, is it possible to memoize operations of BigApprox?

  • Comment on Re^2: Operations with Extremely Large Numbers (BigApprox)

Replies are listed 'Best First'.
Re^3: Operations with Extremely Large Numbers (BigApprox)
by davido (Cardinal) on Nov 09, 2011 at 19:25 UTC

    Yes.

    use Math::BigApprox qw/Fact/; use Benchmark qw/cmpthese/; use Memoize; memoize( 'Fact', INSTALL => 'fastFact' ); our $test = 20000; print "$test!\t=>\t", Fact($test), "\n"; cmpthese ( -5, { Fact => sub{ my $a = Fact($test) }, fastFact => sub{ my $a = fastFact($test) }, } );

    Results...

    20000! => 1.819206e+77337 Rate Fact fastFact Fact 7.89/s -- -100% fastFact 297159/s 3766395% --

    You almost need Math::BigApprox to deal with the percent improvement when memoized. A factorial is one of those "pure functions" where memoization pays off if you intend to use the same params more than once.


    Dave