Flushing caches for benchmarking in Linux
Benchmarking a machine with a surplus of RAM introduces a difference
between the first run and subsequent runs when any disk blocks needed
are already cached. Fortunately, since 2.6.16 there is a mechanism to
discard the caches,
I use this command to drop my caches between benchmark runs.
sync ; echo 3 > /proc/sys/vm/drop_caches
Note: that command was simplified thanks to anonymous’ comment.
As an example, building femtodns currently takes 2.1 seconds with flushed caches and 0.9 seconds on subsequent runs.
You can read more about /
proc/sys/vm/drop_caches at Drop Caches -