I have some code roughly like this
unsafe fn foo(p: *const X) {
let x = *p;
let begin = Instant::now();
... // potentially expensive processing of x
let duration = begin.elapsed();
}
The issue is that due to out-of-order execution, etc., duration
will generally include the time spent waiting for p
to be read from memory. I have reasons to want to benchmark the "potentially expensive processing" without including that waiting time. What can I do? Is this the place for memory barriers/fences? (note that I'm only concerned with single-threaded execution here)