PyCC Documentation¶
PyCC is a Python code optimizer. It rewrites your code to make it faster.
Basic Example¶
Symbol table (variable) lookups don’t seem expensive at first.
# awesome_module.py
MAGIC_NUMBER = 7
for x in xrange(10000000):
MAGIC_NUMBER * MAGIC_NUMBER
Now let’s make a crude benchmark.
# Generate bytecode file to skip compilation at runtime.
python -m compileall awesome_module.py
# Now get a simple timer.
time python awesome_module.pyc
# real 0m0.923s
# user 0m0.920s
# sys 0m0.004s
What does PyCC have to say about it?
pycc-transform awesome_module.py --constants
MAGIC_NUMBER = 7
for x in xrange(10000000):
(7 * 7)
Neat, but what good does that do?
pycc-compile awesome_module.py -- constants
time python awesome_module.pyc
# real 0m0.473s
# user 0m0.469s
# sys 0m0.004s
How To Get It¶
pip install pycc
Source?¶
If you want to file a bug, request an optimization, contribute a patch, or just read through the source then head over to the GitHub page.
License¶
The project is licensed under the Apache 2 license.