Home > Backend Development > Python Tutorial > python计算程序开始到程序结束的运行时间和程序运行的CPU时间

python计算程序开始到程序结束的运行时间和程序运行的CPU时间

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-16 08:46:02
Original
1228 people have browsed it

执行时间

方法1

复制代码 代码如下:

import datetime
starttime = datetime.datetime.now()
#long running
endtime = datetime.datetime.now()
print (endtime - starttime).seconds

方法 2

复制代码 代码如下:

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

方法3

复制代码 代码如下:

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

方法1和方法2都包含了其他程序使用CPU的时间,是程序开始到程序结束的运行时间。
方法3算只计算了程序运行的CPU时间

Related labels:
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