我目前有一个.h5文件,其中的表由三列组成:一个64字符的文本列,一个与文本源有关的UInt32列和一个UInt32列(即文本的xxhash)。该表由〜2.5e9行组成
我正在尝试查找并计算表中每个文本条目的重复项-本质上将它们合并为一个条目,同时对实例进行计数。我尝试通过在哈希列上建立索引,然后循环遍历table.itersorted(hash)
,同时跟踪哈希值并检查冲突-与finding a duplicate in a hdf5 pytable with 500e6 rows非常相似。我没有在遍历表时修改表,而是将合并的条目写到新表中-我将代码放在底部。
基本上,我的问题是整个过程花费的时间太长-我花了大约20个小时才能到达迭代#5 4e5。但是我正在开发HDD,因此完全有可能出现瓶颈。您看到我可以改善我的代码的任何方法,还是可以建议另一种方法?预先感谢您的帮助。
P.S。我保证我不会做任何非法的事情,这只是我的学士论文的大规模泄露密码分析。
ref = 3 #manually checked first occuring hash, to simplify the below code
gen_cnt = 0
locs = {}
print("STARTING")
for row in table.itersorted('xhashx'):
gen_cnt += 1 #so as not to flush after every iteration
ps = row['password'].decode(encoding = 'utf-8', errors = 'ignore')
if row['xhashx'] == ref:
if ps in locs:
locs[ps][0] += 1
locs[ps][1] |= row['src']
else:
locs[ps] = [1, row['src']]
else:
for p in locs:
fill_password(new_password, locs[ps]) #simply fills in the columns, with some fairly cheap statistics procedures
new_password.append()
if (gen_cnt > 100):
gen_cnt = 0
new_table.flush()
ref = row['xhashx']```
您的数据集比参考解决方案大10倍(2.5e9对500e6行)。您是否进行了任何测试以确定时间在哪里? table.itersorted()
方法可能不是线性的-可能会占用大量资源。 (我对itersorted没有任何经验。)
这里的过程可能会更快: