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

Any good way to set group option "on this level"? #8

Open
antifuchs opened this issue Oct 7, 2023 · 0 comments
Open

Any good way to set group option "on this level"? #8

antifuchs opened this issue Oct 7, 2023 · 0 comments

Comments

@antifuchs
Copy link

I'd love to separate out my project's benchmark definitions into multiple files, which divan seems to support via the [[bench]] cargo list method. However, I'd also like to set benchmark group options on each of these files, so that the #[bench] annotations don't have to repeat the same arguments over and over. Is there a good way to do that without introducing an "interim" module in each file?

I've tried:

Having a "main" file that uses submodules:

#[bench_group(threads=THREADS)
mod multi_threaded;

fn main() {
    divan::main();
}

That fails because procmacro annotations on external files are not stable.

Using a module-global bench_group annotation

Same as above, one main.rs file that uses mod multi_threaded; but inside the multi_threaded.rs file,

#![bench_group(threads=THREADS)

This fails because module-wide procmacro annotations aren't stable.

Using an interim module in each benchmark file

Here, put the main function into multi_threaded.rs, then pull in a submodule inside the file as a layer to set those benchmark options on:

fn main() {
    divan::main();
}

#[divan::bench_group(
    threads = THREADS,
)]
mod multi_threaded {
    // ...
}

This works, but results in a tree like:

     Running benches/multi_threaded.rs (target/release/deps/multi_threaded-77aac12e33714668)
multi_threaded                                                                                                                          fastest       │ slowest       │ median        │ mean          │ samples │ iters
╰─ multi_threaded                                                                                                                                     │               │               │               │         │
   ├─ bench_direct                                                                                                                                    │               │               │               │         

...and I'd love to get rid of that interstitial module layer.

Possible solutions

  • Have a main function that accepts benchmark group options?
  • Allow setting the "default" benchmark options as globally-mutable state? (yikes?!)
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