python效能對比

2022-02-18 23:03:22 字數 2270 閱讀 6692

#1

#

-*- coding:utf8-*-

import

datetime

road_nodes ={}

for i in range(5000000):

road_nodes[i] =

beg_time =datetime.datetime.now()

for key, val in

road_nodes.items():

pass

end_time =datetime.datetime.now()

print

"time_scan:

", end_time - beg_time

耗時

$python com_1.py

time_scan: 0:00:17.126098

#2

#

-*- coding:utf8-*-

import

datetime

road_nodes =

for i in range(5000000):

beg_time =datetime.datetime.now()

for key in

road_nodes:

pass

end_time =datetime.datetime.now()

print

"time_scan:

", end_time - beg_time

耗時

$python com_2.py 

time_scan: 0:00:00.325304

#3

#

-*- coding:utf8-*-

import

datetime

road_nodes ={}

for i in range(5000000):

road_nodes[i] =

beg_time =datetime.datetime.now()

for key in

road_nodes:

pass

end_time =datetime.datetime.now()

print

"time_scan:

", end_time - beg_time

耗時

$python  com_3.py 

time_scan: 0:00:00.359197

總結只對於字典key的遍歷,用for key in dic方式  

#1

from datetime import

datetime

a =for i in range(50000):

aim_list =

for i in range(1000000):

beg_time =datetime.now()

for key in

a:

if key in

aim_list:

pass

end_time =datetime.now()

print

"scan:

", end_time - beg_time

執行

$python draw.py

scan: 0:00:38.624985

#2  

from datetime import

datetime

a =for i in range(50000):

aim_list ={}

for i in range(1000000):

aim_list[i] =none

beg_time =datetime.now()

for key in

a:

if key in

aim_list:

pass

end_time =datetime.now()

print

"scan:

", end_time - beg_time

執行

$python  draw2.py 

scan: 0:00:00.014031

分析

巨大的差異由 aim_list型別導致,乙個是list,乙個是dict

for i in ***時,list是乙個個遍歷,效率是o(n);dict是直接找到,效率是o(1)。

python效能對比

1 coding utf8 import datetime road nodes for i in range 5000000 road nodes i beg time datetime.datetime.now for key,val in road nodes.items pass end t...

python效能對比

閱讀目錄 回到頂部 1 coding utf8 import datetime road nodes for i in range 5000000 road nodes i beg time datetime.datetime.now for key,val in road nodes.items ...

SSD效能對比

ssd效能測試 順序寫 16k iops 85061.08 順序寫 8k iops 146250.93 順序寫 4k iops 239816.69 順序寫 2k iops 294540.87 順序寫 1k iops 347170.06 隨機寫 16k iops 21865.24 隨機寫 8k iop...