Crate bencher [] [src]

Simplified stable-compatible benchmark runner.

Almost all user code will only be interested in Bencher and the macros that are used to describe benchmarker functions and the benchmark runner.

NOTE: There's no proper black_box yet in this stable port of the benchmark runner, only a workaround implementation. It may not work exactly like the upstream test::black_box.

One way to use this crate is to use it as dev-dependency and setup cargo to compile a file in benches/ that runs without the testing harness.

In Cargo.toml:

Be careful when using this code, it's not being tested!
[[bench]]
name = "example"
harness = false

In benches/example.rs:

#[macro_use]
extern crate bencher;

use bencher::Bencher;

fn a(bench: &mut Bencher) {
    bench.iter(|| {
        (0..1000).fold(0, |x, y| x + y)
    })
}

fn b(bench: &mut Bencher) {
    const N: usize = 1024;
    bench.iter(|| {
        vec![0u8; N]
    });
 
    bench.bytes = N as u64;
}

benchmark_group!(benches, a, b);
benchmark_main!(benches);

Use cargo bench as usual. A command line argument can be used to filter which benchmarks to run.

Reexports

pub use self::TestFn::*;

Modules

bench
stats

Macros

benchmark_group

Defines a function called $group_name that returns the test description values for the listed functions $function.

benchmark_main

Define a fn main() that will run all benchmarks defined by the groups in $group_name.

Structs

BenchSamples
Bencher

Manager of the benchmarking runs.

TestDesc
TestDescAndFn
TestOpts
TestPaths

Enums

TestFn

Traits

TDynBenchFn

Represents a benchmark function.

Functions

black_box

NOTE: We don't have a proper black box in stable Rust. This is a workaround implementation, that may have a too big performance overhead, depending on operation, or it may fail to properly avoid having code optimized out. It is good enough that it is used by default.

fmt_bench_samples
run_tests_console

Type Definitions

TestName