Home > Mobile >  Python and Windows, py execution time vs real execution time
Python and Windows, py execution time vs real execution time

Time:09-24

I have a simple script, which involve quite fast operations. In order to test the execution time, I measured it:

import time
...

def main():
    ...
    


if __name__ == "__main__":
    stime = time.time()
    main()
    print("\n%s seconds" % (time.time() - stime))

Then I measured the execution time of the whole script:

Measure-Command { python.exe .\myanalyzer.py "f1.png" "f2.png" "f3.txt" | Out-Host }

And the powershell returns:

0.13824200630187988 seconds


Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 4
Milliseconds      : 238
Ticks             : 42382540
TotalDays         : 4.90538657407407E-05
TotalHours        : 0.00117729277777778
TotalMinutes      : 0.0706375666666667
TotalSeconds      : 4.238254
TotalMilliseconds : 4238.254

Where 0.13 is the execution time inside the python and 4.2 is the time involved also to execute the whole python script.

There is a way to decrease windows execution time?

CodePudding user response:

The command you're using to check execution time isn't only showing you script execution time but it is including execution time of Python Interpreter also. You can optimize your script, but you should not worry about interpreter execution time. If you want to increase speed of your "script" more, than you should study about Cython.

CodePudding user response:

4 seconds seems a bit high, but even if your script is very simple, the Windows OS has to load the full Python interpretor, which consists in an executable and several DLLs, then the core Python loads your script compile it into bytecode and finally starts executing it. Still time to load the required modules and finally it can execute your real code.

But 4 seconds seems to me very high. My system only needs 100 to 200 ms to load and execute a trivial script.

  • Related