Python-timeit没有结果 [英] Python - No result from timeit

查看:104
本文介绍了Python-timeit没有结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在test.py中编写了这个简单的代码(在python中).我尝试运行timeit,没有任何错误,但是我没有任何有关运行时间的信息.你能帮我吗?

I wrote this simple code (in python) in test.py. I try to run timeit and I don't have any errors but I don't get any information about the time of run. Can you help me ?

import timeit

def functionsWhile():
    "Desc about function"
    lic = 0
    n = 30000
    while lic<= n:
            lic += 1
    #print "test"
    return lic

t = timeit.Timer("functionsWhile()", "from __main__ import functionsWhile")

try:
    t.repeat(3, 2)
except:
    t.print_exc()

我希望得到(EXAMPLE)之类的结果:

I expect a result such as (EXAMPLE):

$>python test.py
[0.006793975830078125, 0.006793975830078125, 0.006793975830078125]
$>

但是我只有:

$>python test.py
$>

我没有timeit的结果.我使用python 2.7和linux.

I don't have result from timeit. I use python 2.7 and linux.

推荐答案

尝试print t.repeat的结果.

这篇关于Python-timeit没有结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆