difflib を使用して、2 つのディレクトリ (連続した年のバージョン) 内のファイルを比較しています。まず、filecmp を使用して変更されたファイルを見つけ、次に difflib.SequenceMatcher を繰り返し使用してそれらを比較し、ここで説明されているように html diff を生成しています。
しかし、プログラムの実行に時間がかかりすぎており、Python が 100% の CPU を使用していることがわかりました。時間プロファイリングで、seqm.get_opcodes()呼び出しに常に時間がかかっていることがわかりました。
任意の洞察をいただければ幸いです。ありがとう !
コード:
#changed_set contains the files to be compared
for i in changed_set:
oldLines = open(old_dir +"/" + i).read()
newLines = open(new_dir +"/" + i).read()
seqm = difflib.SequenceMatcher(lambda(x): x in string.whitespace, oldLines, newLines)
opcodes = seqm.get_opcodes() #XXX: Lots of time spent in this !
produceDiffs(seqm, opcodes)
del seqm