bluss/bencher

Is there a way to recompile my library for the benchmarks defining some attribute?

Closed this issue · 4 comments

I have some code in my library that is private and used for testing.

I would like to use the code in the benchmarks, but it is not available because it is hidden with the #[cfg(test)] macro. I can make it public as long as it is still hidden behind a macro.

Is there a way to make bencher pass my library an attribute when it is compiling it for the benchmarks? Or is there a way to make bencher use a special version of my library where I pass it a feature flag?

bluss commented

I don't think custom harnesses can support in-crate benchmarks. I haven't explored it at all.

My benchmarks are always in the benches/ directory (not "in crate" I think). I would just want a special version of my library to be used (e.g. one that has been passed a "benches" attribute). That way I could mark my utility code for testing with #[cfg(any(tests, benches))] and use it in benchmarks as well.

bluss commented

I see. I have to pass on the question to cargo, don't know.

Ok, thanks for the answer anyways :)