Home  >  Article  >  Backend Development  >  How to use the time module in Python to monitor program running time

How to use the time module in Python to monitor program running time

尚
Original
2019-07-02 13:21:594572browse

How to use the time module in Python to monitor program running time

Time.time and time.clock can be used in Python to calculate the program running time.

time.time method:

Returns the timestamp of the current time, calculating the time from the beginning of the program to the end of the program.

The code is as follows:

start = time.time()
run_fun()
end = time.time()
print end-start

time.clock method:

Calculates the CPU time of program running

Code As follows:

start = time.clock()
run_fun()
end = time.clock()
print end-start

For more Python-related technical articles, please visit the Python Tutorial column to learn!

The above is the detailed content of How to use the time module in Python to monitor program running time. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn