Cargo bench without extern crate


#1

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!


#2

Try something based on;

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

or maybe include!


#3

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


#4

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?


#5

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


#6

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