-
-
Notifications
You must be signed in to change notification settings - Fork 30
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
Benchmark within crate source code isn't running #26
Comments
Might be that you're not actually using anything from the lib and thus it gets completely removed from your dependency tree. Can you please check if either of the following fixes this?
Yes. That is why Divan has an
Dead code elimination doesn't apply here because the approaches used (pre- |
Ah, yes. I'm probably not using anything from the lib. Will try again. FWIW the workaround I'm using re feature flag is to have the library have a dev-dependency on itself with the benchmark feature enabled. It does mean that benchmarks get compiled into tests but that's generally a small price to pay considering that it does eliminate the benchmark support code for external users. Probably the best that can be done at this time until Cargo/Rust improve the benchmarking ecosystem. |
Here's all I needed to change to make it work: Cargo.toml:
lib.rs:
in benchmark main:
Not the best setup because it forces dependencies needed for running the benchmark itself to be in the |
@vlovich In my tests it seems that you don't need to create the |
Here is my workaround:
Now, running |
@thomaseizinger I believe rust-lang/cargo#1982 would remove the need to pass an explicit feature flag |
The feature flag is required because |
This seems to be same issue as #61. See rust-lang/rust#133491 for upstream discussion. |
I'm trying out Divan on Linux. My project is a workspace layout. Within that workspace I have a crate
foo
. Withinfoo/benches
I create afoo.rs
file that has:and register it within
foo/Cargo.toml
:Then within foo/src/lib.rs I put:
I see "Benchmark main" when I run
cargo bench -p foo
but not "Running registered benchmark". If I move thebench
function tofoo/benches/foo.rs
then everything works. Not sure what I need to do to make this work.Semi-related, does putting benchmark code within the crate mean that downstream dependencies compile the benchmarks? I'm hoping it at least is dead-code stripped but would be good to call this out in the docs.
The text was updated successfully, but these errors were encountered: