[Python-Dev] Benchmarking Python and micro-optimizations (original) (raw)

Victor Stinner victor.stinner at gmail.com
Thu Oct 20 06:56:06 EDT 2016


Hi,

Last months, I worked a lot on benchmarks. I ran benchmarks, analyzed results in depth (up to the hardware and kernel drivers!), I wrote new tools and enhanced existing tools.

For timeit, I suggest to use my perf tool which includes a reliable timeit command and has much more features like --duplicate (repeat the statements to reduce the cost of the outer loop) and --compare-to (compare two versions of Python), but also all builtin perf features (JSON output, statistics, histogram, etc.).

I added benchmarks from PyPy and Pyston benchmark suites to performance: performance 0.3.1 contains 51 benchmark scripts which run a total of 121 benchmarks. Example of tested Python modules:

More benchmarks will be added later. It would be nice to add benchmarks on numpy for example, numpy is important for a large part of our community.

All these (new or updated) tools can now be used to take smarter decisions on optimizations. Please don't push any optimization anymore without providing reliable benchmark results!

My first major action was to close the latest attempt to micro-optimize int+int in Python/ceval.c, http://bugs.python.org/issue21955 : I closed the issue as rejected, because there is no significant speedup on benchmarks other than two (tiny) microbenchmarks. To make sure that no one looses its time on trying to micro-optimize int+int, I even added a comment to Python/ceval.c :-)

https://hg.python.org/cpython/rev/61fcb12a9873 "Please don't try to micro-optimize int+int"

The perf and performance are now well tested: Travis CI runs tests on the new commits and pull requests, and the "tox" command can be used locally to test different Python versions, pep8, doc, ... in a single command.

Next steps:

  1. Maybe also CPython 3.5 and CPython 3.6 if they don't take too much resources.

Links:

See https://pypi.python.org/pypi/performance which contains even more links to Python benchmarks (PyPy, Pyston, Numba, Pythran, etc.)

Victor



More information about the Python-Dev mailing list