Hypergeometric distribution
Scott David Daniels
scott.daniels at acm.org
Mon Jan 2 12:09:11 EST 2006
Raven wrote:
> ...
> def main():
> t = time.time()
> for i in range(1000):
> r = hypergeometric(6,6,30,6)
> print time.time() - t
>
> t = time.time()
> for i in range(1000):
> r = hypergeometric_gamma(6,6,30,6)
> print time.time() - t
>
> and the result is:
>
> 0.0386447906494
> 0.192448139191
>
> The first approach is faster so I think I will adopt it.
>
You should really look into the timeit module -- you'll get nice
solid timings slightly easier to tweak.
Imagine something like:
import timeit
...
t0 = timeit.Timer(stmt='f(6, 6, 30, 6)',
setup='from __main__ import hypergeometric as f')
t1 = timeit.Timer(stmt='f(6, 6, 30, 6)',
setup='from __main__ import hypergeometric_gamma as f')
repetitions = 1 # Gross under-estimate of needed repetitions
while t0.timeit(repetitions) < .25: # .25 = minimum Secs per round
repetitions *= 10
print 'Going for %s repetitions' % repetitions
print 'hypergeometric:', t0.repeat(3, repetitions)
print 'hypergeometric_gamma:', t1.repeat(3, repetitions)
--Scott David Daniels
scott.daniels at acm.org
More information about the Python-list
mailing list