Why does Directory.GetFiles() run faster on subsequent runs?

ⅰ亾dé卋堺 提交于 2019-12-01 05:10:56

问题


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:


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.



来源:https://stackoverflow.com/questions/12519374/why-does-directory-getfiles-run-faster-on-subsequent-runs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!