为什么第一次运行 grep 比连续运行慢几倍?
每次从项目目录构建项目时,我都会运行此命令:
egrep -r -n --include=*.java <my regex> .
而且我无法理解为什么连续运行比第一次运行快 10 倍。实际上我在其他涉及大型目录的磁盘 IO 操作(计算目录大小、代码提交等)中看到了这种行为。 我认为这与操作系统的磁盘IO内部有关。可能它在某种程度上正在缓存。有人能把我的鼻子指向正确的方向吗?
I run this command every time I build my project from the project directory:
egrep -r -n --include=*.java <my regex> .
And I cannot understand why consecutive runs are up to 10 times faster than first one. Actually I have seen this behavior in other disk IO operations involving large directories (calculation directory size, code commits etc.).
I think that it is related to operation system's disk IO internals. Probably it is caching on some level. Can somebody point my nose in right direction?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因为最近访问的文件被操作系统缓存了。
请查看此处。
Because recently accessed files are cached by the operating system.
Have a look here.