Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

pyc

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

like image 610
Shan Avatar asked Feb 28 '12 16:02

Shan


1 Answers

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.

like image 167
jdi Avatar answered Oct 05 '22 00:10

jdi