AFAIK, it's unfortunately not possible to discard the read cache under Windows. I spent some time looking into this some years ago, and only found out how to flush the write cache.
As I see it, you have three options, unless somebody else has found some magic:
- If possible, do your read file I/O in unbuffered mode.
- Each time you want to benchmark, create a new copy of the test data specifying unbuffered mode when creating the new copy (this should keep the copy out of read cache, but I haven't tested).
- Allocate enough memory that windows has to discard the disk cache (ugh!).
EDIT: it is indeed possible to flush the read cache, at least on Vista and later: Disable or flush page cache on Windows. It requires a call to the undocumented NtSetSystemInformation
NT API, though. Also, for a single file, read cache can be flushed simply by opening the file with FILE_FLAG_NO_BUFFERING
specified and closing the handle again.