is there any kind of performance gain while using .pyc files in python?

Shan picture Shan · Feb 28, 2012 · Viewed 8.4k times · Source

We can write a piece of python code and put it in already compiled ".pyc" file and use it. I am wondering that is there any kind of gain in terms of performance or it is just a kind of modular way of grouping the code.

Thanks a lot

Answer

jdi picture jdi · Feb 28, 2012

There is no performance gain over the course of your program. It only improves the startup time.

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.

http://www.network-theory.co.uk/docs/pytut/CompiledPythonfiles.html

And pyo files being the next optimization just remove doc strings from your code.