gbenchmark 0.1.0

A benchmark library for Rust with inspiration from Go benchmarking.
Documentation
  • Coverage
  • 100%
    31 out of 31 items documented1 out of 21 items with examples
  • Size
  • Source code size: 27.08 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 3.2 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • eternal-flame-AD/gbenchmark
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • eternal-flame-AD

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)); 

Example

See src/bin/gbenchmark_demo/main.rs for a quick demo on getting a basic benchmark running.

> cargo run --bin gbenchmark_demo --release
   Compiling gbenchmark v0.1.0 (/home/yume/source/gbenchmark)
    Finished release [optimized] target(s) in 0.29s
     Running `target/release/gbenchmark_demo`
preallocated: 67108864 reps: 1.000 ns/op
push: 67108864 reps: 2.000 ns/op
preallocated: 1 reps: 0 allocs/op, 0 bytes alloc'ed/op
push: 1 reps: 6 allocs/op, 2016 bytes alloc'ed/op