Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Introduce BenchmarkContext argument for closure passed to benchmark function #33

Open
vlovich opened this issue Nov 17, 2023 · 0 comments

Comments

@vlovich
Copy link

vlovich commented Nov 17, 2023

For the bench function on divan::Bencher, I'd like to introduce a BenchmarkContext (naming open to bikeshedding). The motivating use-case is to expose a function called something like inject_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 consume self which is intrinsic to the design.

Happy to actually implement it but was curious about thoughts first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant