2 releases
Uses new Rust 2024
| new 0.1.0-alpha.2 | Feb 26, 2026 |
|---|---|
| 0.1.0-alpha.1 | Jul 6, 2025 |
#409 in Profiling
18KB
423 lines
Haste
Choose a willing creature that you can see within range. Until the spell ends, the target's speed is doubled[..].
-- Dnd 5e Player's Handbook
A work in-progress benchmarking library inspired by divan and criterion.
use haste::Throughput;
// Anywhere in `benches/` or your library!*
#[haste::bench(args = [1, 2, 3], throughput = Throughput::Bytes(arg * 10))]
async fn process_bytes(arg: usize) {
// ..
}
// In your benches/ folder.
// extern crate your_crate; <-- Add this if your benches use no items of your benchmarked library
fn main() {
haste::main();
}
* Note: When registering benchmarks in your library, don't place them in a #[cfg(test)] module, as they won't be compiled. See Benchmarking private APIs
Benchmarking private APIs
You can use Haste to benchmark private functions of your library. Unfortunately, these can't be placed in modules annotated with #[cfg(test)] as the library is not compiled with the test cfg when running cargo bench.
One workaround for this:
"Private" cargo feature
In your Cargo.toml declare e.g. an _internal_benchmarking feature
[features]
# Do not depend on this feature!
_internal_benchmarking = ["dep:haste"]
[dependencies]
haste = { version = "..", optional = true }
By preceding it with _ this feature will not be listed on docs.rs.
Then you can use this feature to cfg your benchmarks in your library with acess to private items.
Dependencies
~1.3–2.5MB
~40K SLoC