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:
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:
That fails because procmacro annotations on external files are not stable.
Using a module-global
bench_group
annotationSame as above, one
main.rs
file that usesmod multi_threaded;
but inside the multi_threaded.rs file,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:This works, but results in a tree like:
...and I'd love to get rid of that interstitial module layer.
Possible solutions
main
function that accepts benchmark group options?