I am quoting a part of Python documentation:
"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."
I don't understand what does it mean when it says it doesn't affect the running time but the loading time? Could someone please explain it a little deep that I can understand completely?
When you import a module test.py, Python must read the source and convert it into the bytecode Python can execute. This takes time, but Python will store this in test.pyc. This Bytecode is the result of breaking your code down into simpler terms able to run directly on the CPython Virtual Machine.
If you load test.pyc, Python doesn't need to compile your source into bytecode before running, so it takes slightly less time to start.
If you import the module test.py twice without modifying it or deleting the generated test.pyc, Python checks for the existence of test.pyc and loads it instead - so the performance benefit is automatic.
Difference between loading time and running time in python?