I have an easy way to compare an array of FileInfo objects with a list of file names to check which files have already been processed. Then the raw list is returned.
The loop of this method iterates around 250,000 FileInfo objects. It takes an indecent amount of time to compete.
Inefficiency is, obviously, a call to the Contains method in a collection of processed files.
First, how can I check to make sure that my suspicion is true regarding the cause, and secondly, how can I improve the process acceleration method?
public static List<FileInfo> GetUnprocessedFiles(FileInfo[] allFiles, List<string> processedFiles)
{
List<FileInfo> unprocessedFiles = new List<FileInfo>();
foreach (FileInfo fileInfo in allFiles)
{
if (!processedFiles.Contains(fileInfo.Name))
{
unprocessedFiles.Add(fileInfo);
}
}
return unprocessedFiles;
}
source
share