Home > Backend Development > Python Tutorial > 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

Release: 2019-07-06 09:02:31
Original
4596 people have browsed it

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
Copy after login

time.clock method:

Calculates the CPU time of program running

Code As follows:

start = time.clock()
run_fun()
end = time.clock()
print end-start
Copy after login

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!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template