I did three tests on a Dictionary that has about 350 thousand items. I needed to see how many items I could iterate over a 30 second period.
My initial test was just loop through the dictionary with no checks and no UI/console updating. It completed just a second after starting the test.
The second test was writing the count to the console. About 23,600 items were reached.
foreach (KeyValuePair<UInt64, MftFile> entry in mftFiles)
{
fileCount++;
Console.WriteLine(fileCount.ToString());
}
I then tested how quickly it would run when updating the form with the count. It reached just a little over 16000 items.
foreach (KeyValuePair<UInt64, MftFile> entry in mftFiles)
{
fileCount++;
MessageReceived(this, GetMessageReceivedEventArgs("Proactive Checks - RIFT",
string.Format("Analyzing Drive {0} - MFT Record {1} of {2}", drive.Name, fileCount.ToString(), mftFiles.Count.ToString()), string.Empty));
}
Doing any kind of conditional logic in the loop slows the loop down by a huge amount. I originally created a stop watch outside of the loop and checked it inside of the loop to see when it had reached a certain time. Over a minute went by and it had only iterated over ~5000 items.
There's a C++ app that does a similar thing to what I'm doing. It takes less than 60 seconds for it to iterate through all 300,000 items, update the UI, find all duplicates, and create hashes for each duplicate.
Is there a better way to iterate through the dictionary?