I don't know for Caliper, but for JMH you can have a @Setup which trashes the cache. Although there are multiple caveats:
- doing this before each benchmark invocation makes us to timestamp each benchmark invocation to separate @Setup time from the benchmark itself, which is very bad from overhead and omission standpoint; this is exacerbated by shorter benchmarks.
- long running benchmark will hydrate the caches back rather quickly (back-envelope calculation: 100 ns for LLC miss, 64 bytes per miss, so it takes ~1.6ms to fully hydrate 1 Mb LLC cache); this is exacerbated by longer benchmarks.
So, both caveats matter in different conditions, and I don't think it is easy to find the sweet spot between them.
-Aleksey.
P.S. Oh yes, you can have a "spoiler" concurrent thread which will trash the cache, but I fail to see how one can use this technique without obliterating the reliability of the experiment.