Skip to content

Commit

Permalink
cleanup, fix docs, add windows test
Browse files Browse the repository at this point in the history
  • Loading branch information
PSeitz committed May 25, 2024
1 parent 27bdcdf commit 9d9df22
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
os:
- ubuntu-latest
- macos-latest
- windows-latest
rust:
- stable
- beta
Expand All @@ -29,6 +30,7 @@ jobs:
override: true

- run: cargo build
- run: cargo test
- run: cargo bench
# test filter parameter for cargo bench
- run: "[ $(cargo bench | wc -l) -gt $(cargo bench 15 | wc -l) ]"
Expand Down
2 changes: 1 addition & 1 deletion src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub trait Bench<'a> {
fn clear_results(&mut self);
}

type CallBench<'a, I> = Box<dyn FnMut(&'a I)>;
pub(crate) type CallBench<'a, I> = Box<dyn FnMut(&'a I)>;

pub(crate) struct NamedBench<'a, I> {
pub name: String,
Expand Down
4 changes: 2 additions & 2 deletions src/bench_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
NamedInput,
};

/// `BenchGroup` is a group of benchmarks run together.
/// `BenchGroup` is a group of benchmarks wich are executed together.
///
pub struct BenchGroup<'a> {
name: Option<String>,
Expand Down Expand Up @@ -44,7 +44,7 @@ impl<'a> BenchGroup<'a> {
self
}

/// Enables throughput reporting. The throughput will be valid for all inputs that are
/// Enables throughput reporting. The `input_size` will be used for all benchmarks that are
/// registered afterwards.
pub fn set_input_size(&mut self, input_size: usize) {
self.input_size_in_bytes = Some(input_size);
Expand Down
10 changes: 3 additions & 7 deletions src/bench_input_group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ pub(crate) type Alloc = &'static dyn PeakMemAllocTrait;
///
/// The ownership of the inputs is transferred
/// to the `InputGroup`. If this is not possible, use [BenchRunner](crate::BenchRunner) instead.
pub struct InputGroup<I = ()> {
pub struct InputGroup<I: 'static = ()> {
inputs: Vec<OwnedNamedInput<I>>,
//benches: Vec<CallBench<'static, I>>,
bench_group: BenchGroup<'static>,
}

Expand Down Expand Up @@ -74,6 +75,7 @@ impl<I: 'static> InputGroup<I> {
InputGroup {
inputs,
bench_group: BenchGroup::new(runner),
//benches: Vec::new(),
}
}
/// Set the peak mem allocator to be used for the benchmarks.
Expand Down Expand Up @@ -134,9 +136,6 @@ impl<I: 'static> InputGroup<I> {

/// Run the benchmarks and report the results.
pub fn run(&mut self) {
//if let Some(name) = &self.name {
//println!("{}", name.black().on_red().invert().bold());
//}
let input_name_to_ordinal: HashMap<String, usize> = self
.inputs
.iter()
Expand All @@ -151,9 +150,6 @@ impl<I: 'static> InputGroup<I> {
|b| b.get_input_name(),
|group| {
let input_name = group[0].get_input_name().to_owned();
//if let Some(input_size) = group[0].get_input_size_in_bytes() {
//self.bench_group.set_input_size(input_size);
//}
self.bench_group.runner.run_group(Some(&input_name), group);
},
);
Expand Down
6 changes: 4 additions & 2 deletions src/bench_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ use peakmem_alloc::*;
use yansi::Paint;

pub(crate) type Alloc = &'static dyn PeakMemAllocTrait;
pub(crate) const NUM_RUNS: usize = 32;

/// Each bench is run N times in a inner loop.
/// The outer loop is fixed. In the outer loop the order of the benchmarks in a group is shuffled.
pub const NUM_RUNS: usize = 32;

/// The main struct to run benchmarks.
///
Expand Down Expand Up @@ -198,7 +201,6 @@ impl BenchRunner {
//
// This has the drawback, that one bench will affect another one.
shuffle(&mut bench_indices, iteration as u64);
//std::thread::yield_now();

for bench_idx in bench_indices.iter() {
if let Some(cache_trasher) = cache_trasher {
Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
)]

//! Binggan (餅乾, bǐng gān, means cookie in Chinese) is a benchmarking library for Rust.
//! It is designed to be simple to use and to provide a good overview of the performance of your code and its memory consumption.
//! It is designed to provide fast and stable results, report peak memory consumption and integrate with perf.
//!
//! It allows arbitrary named inputs to be passed to the benchmarks.
//!
Expand Down Expand Up @@ -45,7 +45,7 @@
//! // Run the benchmark for the group with input `Vec<usize>`
//! fn bench_group(mut runner: InputGroup<Vec<usize>>) {
//! runner.set_alloc(GLOBAL); // Set the peak mem allocator. This will enable peak memory reporting.
//! runner.enable_perf(); // Enable perf integration. This only works on linux.
//! runner.config().enable_perf(); // Enable perf integration. This only works on linux.
//! runner.register("vec", move |data| {
//! test_vec(data);
//! });
Expand Down Expand Up @@ -120,10 +120,10 @@
//! let mut group = runner.new_group();
//! for (input_name, data) in inputs.iter() {
//! group.set_input_size(data.len() * std::mem::size_of::<usize>());
//! group.register_with_input("vec", input_name, data, move |data| {
//! group.register_with_input("vec", data, move |data| {
//! black_box(test_vec(data));
//! });
//! group.register_with_input("hashmap", input_name, data, move |data| {
//! group.register_with_input("hashmap", data, move |data| {
//! black_box(test_hashmap(data));
//! });
//! }
Expand Down

0 comments on commit 9d9df22

Please sign in to comment.