python输出时间程序_Python时间和程序输出

两个选项:

>在您的定时代码中包含“打印”.丑,但嘿.

timer = Timer('print func()', 'from __main__ import func')

print timer.timeit(1)

>如果你所做的一切都是运行你的功能一次,然后省时间模块,并使用相同的方法直接使用代码:

import sys

import time

if sys.platform == "win32":

# On Windows, the best timer is time.clock()

default_timer = time.clock

else:

# On most other platforms the best timer is time.time()

default_timer = time.time

t0 = default_timer()

output = func()

t1 = default_timer()

print output, t1 - t0

如果要多次运行代码,并产生输出,为什么不在timeit函数之外运行代码?你已经不止一次地打电话了:

timer = Timer('func()', 'from __main__ import func')

print timer.timeit(100),

print func()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值