Function scaling::bench_env [−][src]
pub fn bench_env<F, I, O>(env: I, f: F) -> Stats where
F: FnMut(&mut I) -> O,
I: Clone,
Run a benchmark with an environment.
The value env
is a clonable prototype for the “benchmark
environment”. Each iteration receives a freshly-cloned mutable copy of
this environment. The time taken to clone the environment is not included
in the results.
Nb: it’s very possible that we will end up allocating many (>10,000)
copies of env
at the same time. Probably best to keep it small.
See bench
and the module docs for more.
Overhead
Every iteration, bench_env
performs a lookup into a big vector in
order to get the environment for that iteration. If your benchmark
is memory-intensive then this could, in the worst case, amount to a
systematic cache-miss (ie. this vector would have to be fetched from
DRAM at the start of every iteration). In this case the results could be
affected by a hundred nanoseconds. This is a worst-case scenario however,
and I haven’t actually been able to trigger it in practice… but it’s
good to be aware of the possibility.