Crates.io | criterion2 |
lib.rs | criterion2 |
version | 2.0.0 |
source | src |
created_at | 2024-03-15 16:16:16.077378 |
updated_at | 2024-10-31 01:24:02.757529 |
description | Statistics-driven micro-benchmarking library |
homepage | https://bheisler.github.io/criterion.rs/book/index.html |
repository | https://github.com/Boshen/criterion2.rs |
max_upload_size | |
id | 1174881 |
size | 369,668 |
Criterion.rs helps you write fast code by detecting and measuring performance improvements or regressions, even small ones, quickly and accurately. You can optimize with confidence, knowing how each change affects the performance of your code.
criterion is passively-maintained with outdated dependencies.
This is fork is updated with:
clap
replaced with bpaf
to reduce binary size and compilation timecriterion-plot
crate into criterion2
Bencher::iter_with_setup_wrapper
methodIn order to generate plots, you must have gnuplot installed. See the gnuplot website for installation instructions. See Compatibility Policy for details on the minimum supported Rust version.
To start with Criterion.rs, add the following to your Cargo.toml
file:
[dev-dependencies]
criterion = { version = "0.4", features = ["html_reports"] }
[[bench]]
name = "my_benchmark"
harness = false
Next, define a benchmark by creating a file at $PROJECT/benches/my_benchmark.rs
with the following contents:
use criterion::{black_box, criterion_group, criterion_main, Criterion};
fn fibonacci(n: u64) -> u64 {
match n {
0 => 1,
1 => 1,
n => fibonacci(n-1) + fibonacci(n-2),
}
}
fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("fib 20", |b| b.iter(|| fibonacci(black_box(20))));
}
criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);
Finally, run this benchmark with cargo bench
. You should see output similar to the following:
Running target/release/deps/example-423eedc43b2b3a93
fib 20 time: [26.029 us 26.251 us 26.505 us]
Found 11 outliers among 99 measurements (11.11%)
6 (6.06%) high mild
5 (5.05%) high severe
See the Getting Started guide for more details.
The primary goal of Criterion.rs is to provide a powerful and statistically rigorous tool for measuring the performance of code, preventing performance regressions and accurately measuring optimizations. Additionally, it should be as programmer-friendly as possible and make it easy to create reliable, useful benchmarks, even for programmers without an advanced background in statistics.
First, thank you for contributing.
One great way to contribute to Criterion.rs is to use it for your own benchmarking needs and report your experiences, file and comment on issues, etc.
Code or documentation improvements in the form of pull requests are also welcome. If you're not sure what to work on, try checking the Beginner label.
If your issues or pull requests have no response after a few days, feel free to ping me (@bheisler).
For more details, see the CONTRIBUTING.md file.
Criterion.rs supports the last three stable minor releases of Rust. At time of writing, this means Rust 1.59 or later. Older versions may work, but are not guaranteed.
Currently, the oldest version of Rust believed to work is 1.57. Future versions of Criterion.rs may break support for such old versions, and this will not be considered a breaking change. If you require Criterion.rs to work on old versions of Rust, you will need to stick to a specific patch version of Criterion.rs.
Criterion.rs was originally created by Jorge Aparicio (@japaric) and is currently being maintained by Brook Heisler (@bheisler).
Criterion.rs is dual licensed under the Apache 2.0 license and the MIT license.