#coding:utf-8
from timeit import timeit
from timeit import repeat
def createList1():
a = []
for i in range(10000):
a.append(i)
return a
def createList2():
a = [i for i in range(10000)]
return a
a=timeit("createList1()",'from __main__ import createList1',number=1000)
print(a)
a=repeat("createList1()",'from __main__ import createList1',number=1000,repeat=5)
print(a)
a=timeit("createList2()",'from __main__ import createList2',number=1000)
print(a)
a=repeat("createList2()",'from __main__ import createList2',number=1000,repeat=5)
print(a)
python-timeit使用
最新推荐文章于 2024-09-09 00:00:00 发布