After using the program developed in the last post, I was thinking about some ways to optimize it. Then I went to the FileFinder class and saw this:
I pass the filters to the GetFilesInDirectory method and do my filter there. That way, the folders I don’t want aren’t enumerated. For that, I had to make a change in the Config class, adding a new property for the path Regex and initializing it:
With this changes, I could run the program again and measure the differences. That made a great difference. Before the change, the program was taking 160s to enumerate the files and give me 470000 files. After the change, enumerating the files took only 14.5s to give me the same files (I ran the programs three times each to avoid distortions). That’s a huge difference, no?
Then I started to think a little bit more and thought that the Regex could be compiled. So, I made two simple changes in the Config class:
When I ran again the program, it took me 11.5s to enumerate the files. It doesn’t seem much, but it’s a 25% improvement with just a simple change. That was really good. That way, I have a backup program that enumerates files way faster than before.
All the source code for the project is at https://github.com/bsonnino/BackupData