(鱼c)timeit模块详解——准确测量小段代码的执行时间
http://bbs.fishc.com/forum.php?mod=viewthread&tid=55593&extra=page%3D1%26filter%3Dtypeid%26typeid%3D403(把官方文档做的翻译)
作者说很重要,建议通读一下
In [8]: timeit.timeit('"-".join(str(n) for n in range(100))') Out[8]: 22.984303990000626 In [9]: timeit.timeit('"-".join(str(n) for n in range(100))', number=10000) Out[9]: 0.24227962900113198
[root@centos7 ~]# python3 -m timeit '"-".join(str(n) for n in range(100))' 10000 loops, best of 3: 22.4 usec per loop