Oct-07-2022, 04:37 PM
(Oct-07-2022, 04:02 PM)jpezz Wrote: My objective is to have them execute as quickly as possible.Usually, when a program is slow, the bottleneck is not the time it takes to load the program in memory. The actions that you are suggesting such as storing the program in RAM or using compiled Python files only alter the time that it takes to load the program. It will not accelerate the algorithms or the execution of the Python code.
The only case I can think of where this could change things is if the program does almost nothing and the loading time becomes significant with respect to the real execution time.
Compiled Python files .pyc are automatically used when a module such as «spam» is imported and the spam.pyc file is more recent than the spam.py file. Normally you don't need to worry about this.
Here is an example on my computer with a program «pyspam.py» that simply prints «Hi» and does nothing else. As you can see the running time is about the same for the .py file, the .pyc file and the .pyc file copied to ramdisk.
Output:λ time python3 paillasse/pf/pyspam.py
hi
real 0m0,048s
user 0m0,032s
sys 0m0,016s
λ time python3 paillasse/pf/__pycache__/pyspam.cpython-310.pyc
hi
real 0m0,050s
user 0m0,046s
sys 0m0,004s
λ cp paillasse/pf/__pycache__/pyspam.cpython-310.pyc /media/ramdisk
λ time python3 /media/ramdisk/pyspam.cpython-310.pyc
hi
real 0m0,049s
user 0m0,040s
sys 0m0,008s