Raymond Hettinger <raymond.hettin...@gmail.com> added the comment: 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 ---------- nosy: +rhettinger _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue32039> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com