Anagram

montanaro at tttech.com montanaro at tttech.com
Wed Jan 23 16:29:29 EST 2002


    >> Yup... ;-) Factorial is one of those functions that's so easily
    >> written that it's not worth stuffing in a standard module somewhere.

    Alex> ...except maybe when you need it to be *REALLY, REALLY FAST*:

All the more reason not to standardize on something.  Many numerical
algorithms have multiple implementations, each of which have their own
special niche where they beat the pants of their cousins - if you can bear
their limitations.  If you can tolerate round-off error, a floating point
implementation is much faster for values within the range of fp on your
hardware (about 57x faster for n=52 by my simple test using PyInline).  If
you know you're going to be making lots of calls and have some memory to
spare, using a table to save previous results might be worthwhile (I got a
23x speedup for an extreme case - 99.9% hit ratio).  Strangely enough, a
straightforward translation of the iterative Python function to a C function
making libgmp calls was slower than the Python version.

Are-we-in-violent-agreement-here?-ly, yr's,

Skip




More information about the Python-list mailing list