in reply to Re^2: Operations with Extremely Large Numbers (BigApprox)
in thread Operations with Extremely Large Numbers
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
|
|---|