我發現了這個想法的變種,但沒有一個可以讓我(對
python來說很新)到我需要的地方.
這是場景:
>我有一個巨大的27 gig hashfile.txt,它由獨立的字元串組成.
>我需要逐行解析這個檔案,搜尋另一個不那麼大(~800mb)的addresses.txt檔案中的比對項
>找到比對項時,需要将其寫入outfile.txt
我目前的代碼已盡可能優化,但隻能達到150行/秒.考慮到我的hashfile.txt中有超過15億行,任何優化都會有所幫助.
fin = 'hashed.txt'
nonzeros = open('addrOnly.txt', 'r')
fout = open('hits.txt', 'w')
lines = nonzeros.read()
i = 0
count = 0
with open(fin, 'r') as f:
for privkey in f:
address = privkey.split(", ")[0]
if address in lines:
fout.write(privkey)
i = i+1
if i%100 == 0:
count = count + 100
print "Passed: " + str(count)