homepage

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 unutbu
Recipients georg.brandl, unutbu
Date 2008年09月13日.14:07:48
SpamBayes Score 1.2737395e-08
Marked as misclassified No
Message-id <455070.73671.qm@web39602.mail.mud.yahoo.com>
In-reply-to <1220992931.31.0.275267255012.issue3318@psf.upfronthosting.co.za>
Content
Georg, please forgive me. I thought a sample size of 3 was much too small to make a claim about the typical case, but it appears after doing a computer experiment that I was wrong:
#!/usr/bin/env python
from __future__ import division
import timeit
import random
repeat=100
num=100
def test_func():
 l=1
 for idx in range(10000):
 l=l*idx
timer=timeit.Timer('test_func()','from __main__ import test_func')
data=timer.repeat(repeat=repeat,number=num)
def test_timer():
 sample=random.sample(data,3)
 minval=min(sample)
 onerun=random.choice(data)
 return 1 if minval<onerun else 0
successes=[test_timer() for idx in range(repeat)]
print "Those runs for which the claim in the documentation is true:",successes
s=sum(successes)
l=len(successes)
print "probability that the claim is true: %s/%s = %s"%(s,l,s/l)
Returns:
% timeit-statistics.py
Those runs for which the claim in the documentation is true: [0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 1]
probability that the claim is true: 74/100 = 0.74
I'm satisfied the documentation is correct, and I'm really sorry for wasting your time.
History
Date User Action Args
2008年09月13日 14:07:50unutbusetrecipients: + unutbu, georg.brandl
2008年09月13日 14:07:49unutbulinkissue3318 messages
2008年09月13日 14:07:48unutbucreate

AltStyle によって変換されたページ (->オリジナル) /