Message306310
Other caveats:
* The tight, repeated loops tend to have perfect branch prediction rates and 100% L1 cache hit rates that are rarely present in real code.
There should be links to why this matters:
- https://stackoverflow.com/questions/11227809
- https://www.extremetech.com/extreme/188776-how-l1-and-l2-cpu-caches-work-and-why-theyre-an-essential-part-of-modern-chips
* Code timing list.append() or anything else that uses realloc() internally tends to be timing in clean environments where the realloc() extends in-place rather than recopying all the data. This is almost never true in real code.
* Constant folding can produce misleading results.
To time addition, use:
python -m timeit -s "x=2" "x+3"
rather than:
python -m timeit "2+3"
* Timings include global lookups, attribute lookups, and function call overhead in addition to the operation being timed.
Use:
python -m timeit -s "s=list(range(20))" -s "s_index=s.index" "s_index(5)"
rather than:
python -m timeit -s "s=list(range(20))" "s.index(5)"
* Comparative timings should be repeated and interleaved to show whether the timings are noisy or have been affected the processor switching to a lower clock speed to avoid overheating:
time a
time b
time a # expect this to be consistent with the first *a* timing
time b # expect this to be consistent with the first *b* timing |
|
| Date |
User |
Action |
Args |
| 2017-11-15 21:36:15 | rhettinger | set | recipients:
+ rhettinger, barry |
| 2017-11-15 21:36:15 | rhettinger | set | messageid: <1510781775.25.0.213398074469.issue32039@psf.upfronthosting.co.za> |
| 2017-11-15 21:36:15 | rhettinger | link | issue32039 messages |
| 2017-11-15 21:36:15 | rhettinger | create | |
|