We have encountered an unexpected performance issue when traversing directories looking for files using a wildcard pattern.
We have 180 folders each containing 10,000 files. A command line search using dir <pattern> /s completes almost instantly (<0.25 second). However, from our application the same search takes between 3-4 seconds.
We initially tried using System.IO.DirectoryInfo.GetFiles() with SearchOption.AllDirectories and have now tried the Win32 API calls FindFirstFile() and FindNextFile().
Profiling our code using indicates that the vast majority of execution time is spent on these calls.
Our code is based on the following blog post:
We found this to be slow so updated the GetFiles function to take a string search pattern rather than a predicate.
Can anyone shed any light on what might be wrong with our approach?