in reply to Re: Re: Re: What is the fastest pure-Perl implementation of XXX?
in thread What is the fastest pure-Perl implementation of XXX?
By using the built-in operators, you are using floating point, which means that you are only keeping track of a fixed number of digits. Therefore no matter how large the factorial gets (until you overflow floating point), the iterative algorithm never slows down. Divide and conquer will never win because the problem that it is trying to alleviate - that multiplying large numbers takes a lot of operations - never arises. If you're willing to accept an approximation, then you can just use Stirling's formula and go straight to an answer.
But if you ask for precise calculations, whether in a pure Perl implementation or in some lower-level library, my algorithmic comment holds. (Any slowness of pure Perl calls is on top of that.) Try it calculating 1000! or 10_000!. You don't even need to use Benchmark - the time for one calculation becomes painfully visible.
I assumed, of course, that we were looking for precise calculations...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Re: Re: What is the fastest pure-Perl implementation of XXX?
by kvale (Monsignor) on Mar 31, 2004 at 20:20 UTC |