So let’s modify a little bit the factorial function and then
benchmark both by using timeit
. Ideally our factorial function would
need to calculate a value similar to the binomial expansion,
as we have three factorials to calculate in for each binomial in the
Hypergeometric Distribution. So we can add two extra factorial
calculations to our function and perform the multiplication and division
to return the equivalent to the binomial calculation. So the function
would be
1 2 3 4 5 6 7 8 9 10 11 12 

m
and n
are both values of the binomial and n  m
is the subtraction of one by the
other that forms the last factorial to be calculated. This way it makes
easier to time the performance of both functions. In the end the
complete script would look like
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 

The final result of the average for
ten repetitions is as follow fac = 0.10 s binom = 43.24 s choose =
0.000005 s Clearly, the factorial function gets a huge advantage over
the binomial one. So we will modify it a little bit and use it for our
HD script. Clearly the choose
function is the fastest one, so we
will incorporate it on out HD script.