def test():
"""Stupid test function"""
L = []
for i in range(100):
L.append(i)
if __name__ == '__main__':
from timeit import Timer
t = Timer("test()", "from __main__ import test")
print t.timeit()
Note that timeit can also be used from the command line (python -m
timeit -s 'import module' 'module.test()') and that you can run the
statement several times to get a more accurate measurement. Something
I think time command doesn't support directly.
-- jcollado
像这样使用Linux
time
命令:time python file.py
或者你可以在开始和结束时计算出时间差。
在linux下: 时间python script.py
timeit模块是专门为此目的而设计的。
愚蠢的例子如下
相关问题 更多 >
编程相关推荐