为什么Directory.GetFiles()在后续运行中运行得更快? [英] Why does Directory.GetFiles() run faster on subsequent runs?

查看:69
本文介绍了为什么Directory.GetFiles()在后续运行中运行得更快?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不太确定是什么原因造成的,因此,如果我找不到搜索所需的信息,请原谅我。例如:



假设我们有一个包含1,000,000个文件的文件夹。在其上运行Directory.GetFiles()将花费几分钟。但是,立即重新运行仅需几秒钟。为什么会这样?对象是否被缓存在某个地方?我该如何使用原始时间运行它?尝试在完全不同的扇区中读取大量其他目录信息,以清除缓存。


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?

解决方案

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.

这篇关于为什么Directory.GetFiles()在后续运行中运行得更快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆