Open alshdavid opened 1 month ago
It would be great if Rust Analyzer could run individual Divan benchmarks, so let me know what's needed on my end in Divan to support this. I think to support this today, we can invoke cargo bench -- foo_bench::benchmark
to run the specific benchmark.
For context how this works with custom #[test]
attributes is that all of them usually end up generating an original #[test]
attribute at some point. Obviously this isn't the case for custom benchers, since #[bench]
itself is unstable. I think the ideal way would be to have a tool attribute like #[rust_analyzer::runnable(something here that tells r-a how to construct the runnable)]
(https://github.com/rust-lang/rust-analyzer/issues/11556). That has downsides wrt to MSRV though given the tool attribute for r-a only made it into nightly now. We can probably just do heuristics here for the time being for general #[bench]
attributes checking syntactically (I assume most customer bencher are run the same way?).
What does the bench attribute here expand to roughly?
I assume most customer bencher are run the same way?
My understanding is that Divan is the only one using a #[bench]
attribute. The other popular benchmarking harnesses are Criterion and Tango, which do not register benchmarks with attribute macros.
What does the bench attribute here expand to roughly?
Given the following ways to use the attribute in the same file location as the original post:
#[divan::bench]
fn example1() {}
#[divan::bench]
fn example2(b: Bencher) {}
[!NOTE] The two benchmarks only functionally differ in the
BenchEntry.bench
property, and the only platform specific code islink_section
.
Repro
When using the unstable standard library benchmark, I am prompted to run a specific benchmark.
Using a non std benchmarker does not work. Marking a benchmark with
#[bench]
or#[divan::bench]
results in no "run benchmark" prompt appearing when I am not using the built-in unstablebench
.Rust Analyzer Version
v0.3.1958
Rust Version1.78.0
Vscode Version1.89.1