Compiled bytecode

Peter Hansen peter at engcorp.com
Thu Dec 30 01:13:15 CET 2004


LutherRevisited wrote:
> This may be a dumb question, but are there any practical advantages of
> compiling a python application to *.pyo, or *.pyc?  I haven't noticed any
> difference in the performance of text *.py or a bytecompiled file.

The main script is generally not compiled, but all imported
scripts are generally compiled automatically, the first time
they are imported, and never again unless the source changes.

The compilation process is also generally very fast, basically
not noticable if you are dealing with only small and few scripts,
such as perhaps your test cases.

For this reason and others, I would say there's no real
practical advantage *performance-wise* to compiling your
application, and in fact since it happens automatically
anyway, even worrying about it is wasting your time.

Packagers such as py2exe, however, will generally compile
the source to .pyc files and package that, which makes
installation simpler etc., so there are certainly *some*
practical advantages, just not performance-related ones
(generally).

-Peter



More information about the Python-list mailing list