Crate gbenchmark

Source
Expand description

§gbenchmark

A benchmark library for Rust with inspiration from Go benchmarking.

§Concepts

A benchmark in gbenchmark consumes a parameter (which may be how many iterations, how many threads, etc.) and produces one measure (which may be time, memory allocated, etc.). The measure can look at the parameter and last measure to decide whether to finish the benchmark or ask the parameter for more iterations.

§Creating a benchmark

To create a benchmark first declare the parameters and measures you want to use, then use Benchmark::benchmark to benchmark your function.

use std::time::Duration;
use gbenchmark::{
    measure::{TimeMeasure},
    Benchmark, RepetitionParams,
};

let bench = Benchmark::new(
    || RepetitionParams::default(),
    || TimeMeasure::with_min_time(Duration::from_millis(100)),
);
fn expensive_setup() {
    std::thread::sleep(Duration::from_millis(100));
}
fn do_something() {
    std::thread::sleep(Duration::from_millis(10));
}
let result = bench.benchmark(&mut |params, reset| {
    expensive_setup();
    reset();
    for _ in 0..params.nreps {
        do_something();
    }
});
assert!(result.measure.time - Duration::from_millis(9) < Duration::from_millis(2));

Modules§

alloc
The alloc module contains an allocator wrapper that counts allocations.
measure
The measure module contains the Measure trait and some implementations.

Structs§

Benchmark
A Benchmark system,
BenchmarkResult
Final parameters and measure of a benchmark.
RepetitionParams
A simple parameter that doubles the number of repetitions each time.

Traits§

Params
Trait for benchmark parameters.