comparing the contents of two huge text files quickly

前端 未结 3 1707
走了就别回头了
走了就别回头了 2021-02-03 16:44

what i\'m basically trying to do is compare two HUGE text files and if they match write out a string, i have this written but it\'s extremely slow. I was hoping you guys might

3条回答
  •  忘了有多久
    2021-02-03 16:50

    First I'd suggest normalizing both files and putting one of them in a set. This allows you to quickly test whether a specific line is present and reduces the complexity from O(n*n) to O(n).

    Also you shouldn't open and close the file every time you write a line:

    File.AppendAllText(...); // This causes the file to be opened and closed.
    

    Open the output file once at the start of the operation, write lines to it, then close it when all lines have been written.

提交回复
热议问题