Python Forum
Confused about python execution
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Confused about python execution
#2
(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
jpezz likes this post
Reply


Messages In This Thread
Confused about python execution - by jpezz - Oct-07-2022, 04:02 PM
RE: Confused about python execution - by Gribouillis - Oct-07-2022, 04:37 PM
RE: Confused about python execution - by jpezz - Oct-09-2022, 03:54 PM
RE: Confused about python execution - by menator01 - Oct-09-2022, 04:30 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  kill python execution program lebossejames 0 328 Mar-16-2024, 11:16 AM
Last Post: lebossejames
  C++ programmer confused about why Python isn't working the way I intend Radical 2 868 Sep-15-2023, 04:21 AM
Last Post: Radical
  String int confused janeik 7 1,244 Aug-02-2023, 01:26 AM
Last Post: deanhystad
  I am confused with the key and value thing james1019 3 1,057 Feb-22-2023, 10:43 PM
Last Post: deanhystad
  Pandas confused DPaul 6 2,729 Sep-19-2021, 06:45 AM
Last Post: DPaul
  is and '==' i'm confused hshivaraj 6 2,848 Sep-15-2021, 09:45 AM
Last Post: snippsat
  Confused with 'flags' tester_V 10 5,162 Apr-12-2021, 03:03 AM
Last Post: tester_V
  Simple Tic Tac Toe but I'm confused Izith 1 2,326 Sep-26-2020, 04:42 PM
Last Post: Larz60+
  I am really confused with this error. Runar 3 3,188 Sep-14-2020, 09:27 AM
Last Post: buran
  How to to tie the execution of one process to another inside a loop in Python ignorant_wanderer 0 2,101 Jul-11-2020, 03:44 AM
Last Post: ignorant_wanderer

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020