nvzqz / divan

Fast and simple benchmarking for Rust projects
https://nikolaivazquez.com/blog/divan/
Apache License 2.0
924 stars 26 forks source link

Benches in src for lib #2

Closed radevgit closed 11 months ago

radevgit commented 1 year ago

All the given code examples assume the benches are created in /examples/... Is it possible to have benches in /src/something.rs for a library project? I tried to use #[divan::bench] the same way I use the #[test], in every module and used the [dependencies] divan = "0.1.0" in Cargo.toml, however the "cargo bench" does not produce any results (only run tests). Maybe we need some examples how to do it in that case.

nvzqz commented 11 months ago

Divan is able to benchmark internals of a library. As of 558176a, Divan now benchmarks some of its own internals in CI:

https://github.com/nvzqz/divan/blob/558176a34257ceec8f9b63a71e38e44b7af6a7be/src/time/timer.rs#L176-L196

[!NOTE] Your code should not do crate = crate since this only applies to Divan.

Feel free to use 558176a as a guide for benchmarking your own library's internals. That said, this solution is rather clunky and I wish we had something better.

nvzqz commented 11 months ago

cc @realFlowControl @AliciaBytes @CyriacBr @HadrienG2 @IndigoLily