Why is Directory.GetFiles () faster on subsequent launches?

I'm not quite sure what causes this, so please forgive me if I cannot find the information I need to search. Here is an example:

Let's say we have a folder with 1,000,000 files. Running Directory.GetFiles () on this will take several minutes. However, running it again immediately, it only takes a few seconds. Why is this happening? Are objects cached somewhere? How can I run it with original time?

+4
source share
1 answer

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

+4
source

Source: https://habr.com/ru/post/1435365/


All Articles