diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f5065e5..c114ac2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,6 +13,7 @@ jobs: os: - ubuntu-latest - macos-latest + - windows-latest rust: - stable - beta @@ -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) ]" diff --git a/src/bench.rs b/src/bench.rs index bd9179b..510723c 100644 --- a/src/bench.rs +++ b/src/bench.rs @@ -18,7 +18,7 @@ pub trait Bench<'a> { fn clear_results(&mut self); } -type CallBench<'a, I> = Box; +pub(crate) type CallBench<'a, I> = Box; pub(crate) struct NamedBench<'a, I> { pub name: String, diff --git a/src/bench_group.rs b/src/bench_group.rs index d95d647..be35d04 100644 --- a/src/bench_group.rs +++ b/src/bench_group.rs @@ -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, @@ -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); diff --git a/src/bench_input_group.rs b/src/bench_input_group.rs index c5ea671..39b34ff 100644 --- a/src/bench_input_group.rs +++ b/src/bench_input_group.rs @@ -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 { +pub struct InputGroup { inputs: Vec>, + //benches: Vec>, bench_group: BenchGroup<'static>, } @@ -74,6 +75,7 @@ impl InputGroup { InputGroup { inputs, bench_group: BenchGroup::new(runner), + //benches: Vec::new(), } } /// Set the peak mem allocator to be used for the benchmarks. @@ -134,9 +136,6 @@ impl InputGroup { /// 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 = self .inputs .iter() @@ -151,9 +150,6 @@ impl InputGroup { |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); }, ); diff --git a/src/bench_runner.rs b/src/bench_runner.rs index 267c4f0..0cbdc6f 100644 --- a/src/bench_runner.rs +++ b/src/bench_runner.rs @@ -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. /// @@ -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 { diff --git a/src/lib.rs b/src/lib.rs index 126acd2..9f4ea9f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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. //! @@ -45,7 +45,7 @@ //! // Run the benchmark for the group with input `Vec` //! fn bench_group(mut runner: InputGroup>) { //! 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); //! }); @@ -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::()); -//! 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)); //! }); //! }