RFC: Introduce BenchmarkContext
argument for closure passed to benchmark function
#33
Labels
enhancement
New feature or request
For the
bench
function ondivan::Bencher
, I'd like to introduce aBenchmarkContext
(naming open to bikeshedding). The motivating use-case is to expose a function called something likeinject_simulated_delay
which can be used to add simulated overhead to the benchmark without needing to actually do it. An example of this is for example benchmarking a caching algorithm that would normally do expensive I/O on a miss. In practice, it's more convenient in a microbenchmark to simulate performance by just simulating how long I think the I/O would take.You can hang other state off the context too (e.g. what sample/iteration the current iteration is on in case that matters for some applications).
Not sure if there's any better alternative to make this work since
bench
functions consumeself
which is intrinsic to the design.Happy to actually implement it but was curious about thoughts first.
The text was updated successfully, but these errors were encountered: