标签:pytho col 导入 imp 测试 指定 number 性能测试 +=
# timeit是python中性能测试包
import timeit
def a():
num = 0
i = 0
while i < 10 *6:
num += 1
i += 1
print(num)
def b():
num1 = 0
for i in range(10**6):
num1 += 1
print(num1)
# Timer在一个独立运行环境,需要导入当前函数,timeit是指定运行次数
timer = timeit.Timer("a()","from __main__ import a").timeit(number=1)
timer1 = timeit.Timer("b()", "from __main__ import b").timeit(number=1)
print(timer,timer1)
标签:pytho col 导入 imp 测试 指定 number 性能测试 +=
原文地址:http://www.cnblogs.com/ppansj/p/7977496.html