Why does Directory.GetFiles() run faster on subseq

2020-03-25 07:31发布

I'm not really sure what causes this so please forgive me if I couldn't find the information I needed in a search. Here is an example:

Let's say that we have a folder with 1,000,000 files. Running Directory.GetFiles() on that will take a few minutes. However, running it again right after will take only a few seconds. Why does this happen? Are the objects being cached somewhere? How can I run it with the original time?

1条回答
再贱就再见
2楼-- · 2020-03-25 07:58

Hard drives have internal caches that will help speed up subsequent reads. Try reading a bunch of other directory information in a completely different sector to clear the cache.

查看更多
登录 后发表回答