Skip to content

Why the second search can be faster much than the first time? #2687

Answered by BurntSushi
fang13 asked this question in Q&A
Discussion options

You must be logged in to vote

It somewhat depends on the operating system you're using, but generally speaking, all modern operating systems have a cache of the contents of recently read files in main memory. This means that subsequent reads of that file will not actually read from your disk, but from your RAM instead. Reading from RAM is typically much faster (by orders of magnitude, depending on how slow your disk is). Since these days folks tend to have a lot of RAM, even if you're searching a large file or a large code repository, it's plausible that it will fit into your RAM and subsequent searches will be a lot faster.

This is also why you don't usually need an index to speed up searches for even sizeable code r…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by BurntSushi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants