计算Python代码运行时间

计算Python代码运行时间

使用time包中的time.time()方法可以进行时间的过去。

查看API文档(3.6.5),给出的解释如下所示:

Return the time in seconds since the epoch as a floating point number. The specific date of the epoch and the handling of leap seconds is platform dependent. On Windows and most Unix systems, the epoch is January 1, 1970, 00:00:00 (UTC) and leap seconds are not counted towards the time in seconds since the epoch. This is commonly referred to as Unix time. To find out what the epoch is on a given platform, look at gmtime(0).

返回的就是从1970年1月1日到现在时间(秒)。

可以在程序的开始和结尾,分别调用这个函数,取差值就是大致程序运行的时间。

import time

start = time.time()

# func()

end = time.time()

print(end - start)

输出的就是程序大致运行的时间,单位为秒。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值