-
-
Notifications
You must be signed in to change notification settings - Fork 30.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Have timeit warn about runs that are not independent of each other #67740
Comments
IPython 3.0 added a useful feature that we ought to consider for inclusion either in timeit.repeat() or in the command-line interface: """Using %timeit prints warnings if there is at least a 4x difference in timings between the slowest and fastest runs, since this might meant that the multiple runs are not independent of one another.""" |
How it looks? |
See attached |
This seems like it probably will report something useless (and ultimately be disabled) on PyPy, where runs before and after the JIT will display significant variance. |
May be add an option to control a warning (e.g. turn it off when Python run with -Wignore)? May be write warning to stderr? |
I think for PyPI its actually important here - the JIT'd state of the code is essentially global state being mutated - you can't assess how fast the code is without first warming up the JIT, and if it warms up half way through your fastest run, you're still not actually finding out what you might want to find out. E.g. do you want to know:
Personally, I think as a first approximation, warning about massive variance is a good thing. We could add an option to turn it off, and we could also look at hooking properly into the jit to allow detection of stable state and benchmark only from there on in. But those extra things don't detract from the utility of warning about suspect runs. |
Reviewed on rietvald. |
Here is a patch that emits a warning using the warnings module. The warning is output to stderr and can be suppressed with the -Wignore option, as all other warnings. $ ./python -m timeit -n1 -r 10 -s "import time, random" -- "time.sleep(random.random())"
1 loops, best of 10: 79.6 msec per loop
:0: UserWarning: These test results likely aren't reliable. The worst
time was more than four times slower than the best time.
$ ./python -Wignore -m timeit -n1 -r 10 -s "import time, random" -- "time.sleep(random.random())"
1 loops, best of 10: 16.2 msec per loop |
Implemented Robert's suggestion. $ ./python -m timeit -n1 -r 10 -s "import time, random" -- "time.sleep(random.random())"
1 loops, best of 10: 30.2 msec per loop
:0: UserWarning: The test results are likely unreliable. The worst
time (946 msec) was more than four times slower than the best time. |
New changeset 2e9cf58c891d by Robert Collins in branch 'default': |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: