[][src]Struct criterion::ParameterizedBenchmark

pub struct ParameterizedBenchmark<T: Debug> { /* fields omitted */ }

Structure representing a benchmark (or group of benchmarks) which take one parameter.

Methods

impl<T> ParameterizedBenchmark<T> where
    T: Debug + 'static, 
[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.

Sample size must be at least 2.

Panics

Panics if set to zero or one.

pub fn warm_up_time(self, dur: Duration) -> Self[src]

Changes the warm up time for this benchmark

Panics

Panics if the input duration is zero

pub fn measurement_time(self, dur: Duration) -> Self[src]

Changes the target measurement time for this benchmark. Criterion will attempt to spent approximately this amount of time measuring the benchmark. With a longer time, the measurement will become more resilient to transitory peak loads caused by external programs.

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, I>(id: S, f: F, parameters: I) -> ParameterizedBenchmark<T> where
    S: Into<String>,
    F: FnMut(&mut Bencher, &T) + 'static,
    I: IntoIterator<Item = T>, 
[src]

Create a new parameterized benchmark group and adds the given function to it. The function under test must follow the setup - bench - teardown pattern:

Example

fn bench(c: &mut Criterion) {
    let parameters = vec![1u64, 2u64, 3u64];

    // One-time setup goes here
    c.bench(
        "my_group",
        ParameterizedBenchmark::new(
            "my_function",
            |b, param| b.iter(|| {
                // Code to benchmark using param goes here
            }),
            parameters
        )
    );
}

criterion_group!(benches, bench);
criterion_main!(benches);

pub fn new_external<S, F, I>(
    id: S,
    program: F,
    parameters: I
) -> ParameterizedBenchmark<T> where
    S: Into<String>,
    F: FnMut(&T) -> Command + 'static,
    I: IntoIterator<Item = T>, 
[src]

Deprecated since 0.2.6:

External program benchmarks were rarely used and are awkward to maintain, so they are scheduled for deletion in 0.3.0

Create a new parameterized 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

You can pass the argument to the program in any way you choose.

// Example of an external program that implements this protocol

fn main() {
    let stdin = io::stdin();
    let ref mut stdin = stdin.lock();

    // You might opt to pass the parameter to the external command as
    // an environment variable, command line argument, file on disk, etc.
    let parameter = env::var("PARAMETER").unwrap();

    // 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 using the parameter 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) -> ParameterizedBenchmark<T> where
    S: Into<String>,
    F: FnMut(&mut Bencher, &T) + 'static, 
[src]

Add a function to the benchmark group.

Example

ParameterizedBenchmark::new("times 10", |b, i| b.iter(|| i * 10), vec![1, 2, 3])
    .with_function("times 20", |b, i| b.iter(|| i * 20));

pub fn with_program<S, F>(self, id: S, program: F) -> ParameterizedBenchmark<T> where
    S: Into<String>,
    F: FnMut(&T) -> Command + 'static, 
[src]

Deprecated since 0.2.6:

External program benchmarks were rarely used and are awkward to maintain, so they are scheduled for deletion in 0.3.0

Add an external program to the benchmark group.

Example

ParameterizedBenchmark::new("internal", |b, i| b.iter(|| i * 10), vec![1, 2, 3])
    .with_program("external", |i| {
        let mut command = Command::new("my_external_benchmark");
        command.arg(format!("{:?}", i));
        command
    });

pub fn throughput<F>(self, throughput: F) -> ParameterizedBenchmark<T> where
    F: Fn(&T) -> Throughput + 'static, 
[src]

Use the given function to calculate the input size for a given input.

Example

ParameterizedBenchmark::new("strlen", |b, s| b.iter(|| s.len()), vec!["foo", "lorem ipsum"])
    .throughput(|s| Throughput::Bytes(s.len() as u32));

Trait Implementations

impl<T> BenchmarkDefinition for ParameterizedBenchmark<T> where
    T: Debug + 'static, 
[src]

Auto Trait Implementations

Blanket Implementations

impl<T> From for T[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.