You're doing the computation in a way that entirely misses my point.

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...


In reply to Re: Re: Re: Re: What is the fastest pure-Perl implementation of XXX? by tilly
in thread What is the fastest pure-Perl implementation of XXX? by dragonchild

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.