Struct criterion::Benchmark
[−]
[src]
pub struct Benchmark { /* fields omitted */ }
Structure representing a benchmark (or group of benchmarks) which takes no parameters.
Methods
impl Benchmark
[src]
pub fn sample_size(self, n: usize) -> Self
[src]
Changes the size of the sample for this benchmark
A bigger sample should yield more accurate results, if paired with a "sufficiently" large measurement time, on the other hand, it also increases the analysis time
Panics
Panics if set to zero
pub fn warm_up_time(self, dur: Duration) -> Self
[src]
pub fn measurement_time(self, dur: Duration) -> Self
[src]
Changes the measurement time for this benchmark
With a longer time, the measurement will become more resilient to transitory peak loads caused by external programs
Note: If the measurement time is too "low", Criterion will automatically increase it
Panics
Panics if the input duration in zero
pub fn nresamples(self, n: usize) -> Self
[src]
Changes the number of resamples for this benchmark
Number of resamples to use for the bootstrap
A larger number of resamples reduces the random sampling errors, which are inherent to the bootstrap method, but also increases the analysis time
Panics
Panics if the number of resamples is set to zero
pub fn noise_threshold(self, threshold: f64) -> Self
[src]
Changes the noise threshold for this benchmark
This threshold is used to decide if an increase of X%
in the execution time is considered
significant or should be flagged as noise
Note: A value of 0.02
is equivalent to 2%
Panics
Panics is the threshold is set to a negative value
pub fn confidence_level(self, cl: f64) -> Self
[src]
Changes the confidence level for this benchmark
The confidence level is used to calculate the confidence intervals of the estimated statistics
Panics
Panics if the confidence level is set to a value outside the (0, 1)
range
pub fn significance_level(self, sl: f64) -> Self
[src]
Changes the significance level for this benchmark
The significance level is used for hypothesis testing
Panics
Panics if the significance level is set to a value outside the (0, 1)
range
pub fn plot_config(self, new_config: PlotConfiguration) -> Self
[src]
Changes the plot configuration for this benchmark.
pub fn new<S, F>(id: S, f: F) -> Benchmark where
S: Into<String>,
F: FnMut(&mut Bencher) + 'static,
[src]
S: Into<String>,
F: FnMut(&mut Bencher) + 'static,
Create a new benchmark group and adds the given function to it. The function under test must follow the setup - bench - teardown pattern:
use self::criterion::{Bencher, Criterion, Benchmark}; fn routine(b: &mut Bencher) { // Setup (construct data, allocate memory, etc) b.iter(|| { // Code to benchmark goes here }) // Teardown (free resources) } Criterion::default() .bench("routine", Benchmark::new("routine", routine));
pub fn new_external<S>(id: S, program: Command) -> Benchmark where
S: Into<String>,
[src]
S: Into<String>,
Create a new benchmark group and add the given program to it. The program under test must implement the following protocol:
- Read the number of iterations from stdin
- Execute the routine to benchmark that many times
- Print the elapsed time (in nanoseconds) to stdout
fn main() { let stdin = io::stdin(); let ref mut stdin = stdin.lock(); // For each line in stdin for line in stdin.lines() { // Parse line as the number of iterations let iters: u64 = line.unwrap().trim().parse().unwrap(); // Setup // Benchmark let start = Instant::now(); // Execute the routine "iters" times for _ in 0..iters { // Code to benchmark goes here } let elapsed = start.elapsed(); // Teardown // Report elapsed time in nanoseconds to stdout println!("{}", elapsed.to_nanos()); } }
pub fn with_function<S, F>(self, id: S, f: F) -> Benchmark where
S: Into<String>,
F: FnMut(&mut Bencher) + 'static,
[src]
S: Into<String>,
F: FnMut(&mut Bencher) + 'static,
Add a function to the benchmark group.
Benchmark::new("return 10", |b| b.iter(|| 10)) .with_function("return 20", |b| b.iter(|| 20));
pub fn with_program<S>(self, id: S, program: Command) -> Benchmark where
S: Into<String>,
[src]
S: Into<String>,
Add an external program to the benchmark group.
Benchmark::new("internal", |b| b.iter(|| 10)) .with_program("external", Command::new("my_external_benchmark"));
pub fn throughput(self, throughput: Throughput) -> Benchmark
[src]
Set the input size for this benchmark group.
Benchmark::new("strlen", |b| b.iter(|| "foo".len())) .throughput(Throughput::Bytes(3));