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: Ability to add post-result counters after #34

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

RFC: Ability to add post-result counters after #34

vlovich opened this issue Nov 17, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@vlovich
Copy link

vlovich commented Nov 17, 2023

I was benchmarking a cache library and would like to have the output contain a result of the cache hit rate so that I can understand the benchmark performance across multiple dimensions. I'm thinking something like:

let mut hits = 0;
let mut misses = 0;
b
.output_counter(|| counter::Ratio::new("Hit performance", hits, hits + misses))
.bench(|| {
   // adjust hits & misses
})

It's a little bit complicated since hits & misses borrowing is not going to work like that without unsafe / RefCell / atomics. An alternative approach could be for .bench to return something:

let mut hits = 0;
let mut misses = 0;
b.bench(|| {
   // adjust hits & misses
  (hits, misses)
}).output_counter(|(hits, misses)| counter::Ratio::new("Hit performance", hits, hits + misses))

This is all a bit hand-wavy as I don't have the exact details in mind about the API (open to suggestions), but curious if there's any interest in me adding something like this.

@nvzqz nvzqz added the enhancement New feature or request label Nov 20, 2023
@nvzqz
Copy link
Owner

nvzqz commented Nov 20, 2023

I haven't had time to think much about custom counters (planned), so I'm curious how you think Ratio should be displayed?

I know how Bencher::output_counter could be implemented, so that could be done relatively soon. Currently I'm prioritizing #18, async, and runtime arguments (as opposed to consts).

@vlovich
Copy link
Author

vlovich commented Nov 21, 2023

An example of displaying it would be something like

      56.14 ms
      1.781 Mitem/s
      0.86 Hit performance

I have no strong feelings on the matter though.

I'm happy to help put up a PR if you'd like any help (& if you have a specific way you want it implemented just let me know).

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

No branches or pull requests

2 participants