Python time clock()方法

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/shelbaydo/article/details/84668514

该函数有两个功能,
在第一次调用的时候,返回的是程序运行的实际时间;
以第二次之后的调用,返回的是自第一次调用后,到这次调用的时间间隔
在win32系统下,这个函数返回的是真实时间(wall time),而在Unix/Linux下返回的是CPU时间。

#!/usr/bin/python
import time

def procedure():
    time.sleep(2.5)

# measure process time
t0 = time.clock()
procedure()
print time.clock() - t0, "seconds process time"

# measure wall time
t0 = time.time()
procedure()
print time.time() - t0, "seconds wall time"
2.49965290348 seconds process time
2.5 seconds wall time

猜你喜欢

转载自blog.csdn.net/shelbaydo/article/details/84668514
今日推荐