This article is a mirror article of machine translation, please click here to jump to the original article.

View: 16030|Reply: 0

[Tips] Several Python execution time calculation methods

[Copy link]
Posted on 4/23/2018 3:54:36 PM | | | |
First of all, let's talk about the pitfalls I encountered, the problems encountered in production, I schedule the execution of the python script and monitor the process, the python script running time is far greater than the program execution time I count in the python script.
The time to monitor the execution of python scripts is 36 hours, while the time of self-execution in python scripts is about 4 hours.
The first thing that comes to mind after the problem is that there is a problem with Linux, and I found no abnormalities in various logs.
Then I think of the py2neo used in python to write data asynchronously, blocking the execution of the process.
Finally, the problem was found: the way the python script uses time.clock() to count the execution time of the CPU, not the execution time of the program.
Next, let's compare several Python time statistics:

Method 1:

datetime.datetime.now() gets the current date, and after the program execution ends, the time value obtained by this method is the time of program execution.

Method 2:

time.time() to get the current time since the epoch (In seconds)。 If the system clock provides them, there may be a fraction of seconds. So this place returns a floating-point type. What is obtained here is also the execution time of the program.

Method 3:

time.clock() returns the CPU time since the program started or was first called. This has as much precision as system recording. The return is also a floating-point type. What you get here is the execution time of the CPU.
Note: Program execution time = CPU time + io time + hibernation or waiting time

Here is how I test the execution time of the function using method 2:







Previous:python 3.6.5 installation tutorial under Windows
Next:The Evolution of Neural Network Architecture: A comprehensive review of more than ten architectures from LeNet5 to ENet
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com