Cargo bench without extern crate

To use cargo bench, it seems the standard way is to have a benches directory in the same level as src, import the current library via extern crate ..., and then run the benchmarks. However, what if there're some internal APIs that I want to run benchmarks on, but don't want to expose them to outside. Is there a way to achieve that?

Thanks!

Try something based on;

#[path="../src/file.rs"]
mod file;

or maybe include!

You can use cfg(test) to expose internals only for testing/bench.

2 Likes

Thanks! do you have any example with this approach? does it mean these internals are only exposed for testing but cannot be used by other component (outside test) in the same library?

alternatively, you can try using https://japaric.github.io/criterion.rs/book/index.html

This looks really nice. Will definitely take a look. Thanks!