Original title: Warn about unreliable tests in timeit’s python interface, not just in the command line
Currently, when using timeit’s command line, if the test results vary too much, you get a very nice warning:
> python -m timeit -n 1000 "import this"
The Zen of Python, by Tim Peters
...
Namespaces are one honking great idea -- let's do more of those!
1000 loops, best of 5: 88.8 nsec per loop
:0: UserWarning: The test results are likely unreliable. The worst time (8.1 usec) was more than four times slower than the best time (88.8 nsec).
But when running the same thing in Python:
import timeit
>>> timeit.timeit("import this", number=1000)
# The Zen of Python, by Tim Peters
# ...
# Namespaces are one honking great idea -- let's do more of those!
# 0.0014674999983981252
I think it would be better to move this check for unreliable tests outside of timeit.main
(which is used for timeit’s command-line interface), to timeit.Timer.repeat
, which timeit.main
internally calls.
This should be a pretty simple change, it would be more consistent, and since it’s already deemed useful for timeit’s command-line interface’s users, and the Python usage is usually for the same purposes, I don’t see why it wouldn’t be useful for that too.
Disclaimer: I haven't faced this issue myself
I want to be open about the fact that I haven’t faced this issue myself. I understand that this makes this idea “artificial” as I can’t confirm it has been a problem for everyone.
The reason I’m still doing this is that I still believe it’s an objective improvement, and that I’ve been reading (and commenting) the ideas section for a few months in preparation of participating more, and I believe the best way to start is from small ideas.
I still ask people will take this idea for what it is, and not dismiss it because of this, but I understand it has an effect.
Waiting to hear what you all think,
Thanks in advance!