This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mark.dickinson
Recipients kellerfuchs, mark.dickinson, rhettinger, steven.daprano, tim.peters
Date 2018-12-07.08:42:05
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <[email protected]>
In-reply-to
Content
For some ranges of inputs, it may make sense to use the apparently naive implementation `factorial(n) // factorial(k) // factorial(n - k)`. The current factorial implementation is significantly optimised, and using it directly may be faster than using an iterative solution.

Here are some timings (Python 3.7.1, macOS 10.13), using Raymond's `comb` function from msg331257:

In [5]: %timeit comb(1000, 600)
186 µs ± 442 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)

In [6]: %timeit factorial(1000) // factorial(600) // factorial(400)
97.8 µs ± 256 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)

In [7]: %timeit factorial(1000) // (factorial(600) * factorial(400))
91.1 µs ± 789 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)

But that's just one set of inputs, on one system; your results may vary.
History
Date User Action Args
2018-12-07 08:42:05mark.dickinsonsetrecipients: + mark.dickinson, tim.peters, rhettinger, steven.daprano, kellerfuchs
2018-12-07 08:42:05mark.dickinsonsetmessageid: <[email protected]>
2018-12-07 08:42:05mark.dickinsonlinkissue35431 messages
2018-12-07 08:42:05mark.dickinsoncreate