发布时间:2019-08-06 13:56:23编辑:auto阅读(1709)
#!/usr/bin/env
import datetime
class adair:
def test1(n):
lst=[]
for i in range(n*10000):
lst = lst + [i]
return lst
def test2(n):
for i in range(n*10000):
lst = lst.append(i)
return lst
def test3(n):
return [i for i in range(n*10000)]
def test4(n):
return list(range(n*10000)
if __name__ == '__main__':
f=adair()
start = datetime.datetime.now()
f.test1(2)
end = datetime.datetime.now()
print(end-start)
start = datetime.datetime.now()
f.test2(2)
end=datetime.datetime.now()
print(end-start)
start=datetime.datetime.now()
f.test3(2)
end=datetime.datetime.now()
print(end-start)
start=datetime.datetime.now()
f.test4(2)
end=datetime.datetime.now()
print(end-start)
测试结果如下:
上一篇: Python之石头剪刀布
下一篇: Python学习—json模块
47495
45796
36794
34326
28969
25599
24444
19612
19112
17634
5467°
6049°
5571°
5639°
6574°
5377°
5379°
5886°
5856°
7172°