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 <1544172125.63.0.788709270274.issue35431@psf.upfronthosting.co.za>
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: <1544172125.63.0.788709270274.issue35431@psf.upfronthosting.co.za>
2018-12-07 08:42:05mark.dickinsonlinkissue35431 messages
2018-12-07 08:42:05mark.dickinsoncreate