Python's Performance

Fredrik Lundh fredrik at pythonware.com
Tue Oct 11 13:12:24 EDT 2005


Ognen Duzlevski wrote:

> I am curious, does this make a difference speed wise (aside
> from loading time)? The python tutorial would seem to imply
> that it does not:
>
> >From Python-Docs-2.4.2/tut/node8.html#SECTION008120000000000000000
>
> "A program doesn't run any faster when it is read from a .pyc
> or .pyo file than when it is read from a .py file; the only thing
> that's faster about .pyc or .pyo files is the speed with which
> they are loaded."

if Python decides that the PYC (or PYO) file can be used, it does
the following

    create module
    load module code
    execute module code in module context

if it decides to use the source instead, it does:

    create module
    compile module source into module code
    save module code to PYC (or PYO) file, if possible
    execute module code in module context

so if "loading time" covers the "compiling and saving" time, it's a wash.
even if you don't include compilation in load time, the difference is still
marginal, at least for moderately-sized modules.

</F>






More information about the Python-list mailing list