Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start a program with cold cache

Tags:

c

linux

gcc

x86-64

I run a benchmark several times, to note down the mean reading. But I notice that after the first run, the subsequent runs are faster. I guess it has something to do with the Instruction Cache, so when I run the program next time, the benchmark already has instructions in the cache. Is there a way to start a program with both cold instruction and data caches?

like image 922
MetallicPriest Avatar asked May 24 '13 09:05

MetallicPriest


1 Answers

This is a normal behavior. One way to avoid this problem is run few warm up before the main run. These warm up runs will overwrite the cache memory that grown up previously running program. While calculating the mean value, exclude the warm up runs values only take real run. A various bench marking tools out there which takes these approach like. kernbench, lmbench etc. Where a warmup value is available.

And, if the benchmark you're running depends on data that needs to read from disk then, disk caching has some impact too, one way to avoid is to caching those data onto ram, if possible. This technique is used in kernbench, to avoid, disk cache related issue.

like image 182
rakib_ Avatar answered Oct 05 '22 23:10

rakib_