python代码效率
1 minute read
0x00 两种读文件的不同效率
#第一种:f=open(),for each in f
import time
start=time.clock()
count=0
f=open("webshell_passwords.txt","r+")
for each in f:
count+=1
end=time.clock()
print end-start
f.close()
#第二种:f=open(),all=f.readlines(),for each in all
start1=time.clock()
count1=0
f=open("webshell_passwords1.txt","r+")
all=f.readlines()
for each in all:
count1+=1
end1=time.clock()
print end1-start1
f.close()
'''
输出:
0.001017
0.001255
结论:
f.readlines()是多余的运作,这样浪费系统资源
'''