From 5f201be1d8b220c4a7859e505de90634f32b9d04 Mon Sep 17 00:00:00 2001 From: Trivernis Date: Fri, 3 Apr 2020 11:30:41 +0200 Subject: [PATCH] Add option to print the benchmarkers settings --- Cargo.toml | 2 +- src/benching.rs | 11 +++++++++++ src/lib.rs | 16 ++++++++++++---- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3843091..5cc6f44 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "benchlib-rs" -version = "0.2.0" +version = "0.2.1" authors = ["Trivernis "] edition = "2018" license-file = "LICENSE" diff --git a/src/benching.rs b/src/benching.rs index 1f8f71d..ee252b3 100644 --- a/src/benching.rs +++ b/src/benching.rs @@ -199,4 +199,15 @@ impl Bencher { self } + + /// Prints the settings of the Bencher + pub fn print_settings(&mut self) -> &mut Self { + println!("{}{}Benchmarking Settings{}", color::Fg(color::Green), style::Framed, style::Reset); + println!("Number of iterations:\t {}", if self.iterations > 0 {self.iterations.to_string() } else { "auto".to_string() }); + if self.iterations == 0 { + println!("Maximum number of iterations: {}", self.max_auto_iterations) + } + + self + } } \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 5f8c2bb..22300ba 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,7 +5,7 @@ mod tests { use super::benching::Bencher; #[test] - fn bencher_works() { + fn it_works() { let mut bencher = Bencher::new(); let mut executed = false; bencher.bench("lol", || executed = true); @@ -13,7 +13,7 @@ mod tests { } #[test] - fn bench_iterations() { + fn it_benches_specifically() { let mut bencher = Bencher::new(); let mut count = 0; bencher.set_iterations(243); @@ -22,7 +22,7 @@ mod tests { } #[test] - fn bench_auto() { + fn it_benches_automatically() { let mut bencher = Bencher::new(); let mut count = 0; bencher.set_iterations(0).set_max_iterations(1000); @@ -31,10 +31,18 @@ mod tests { } #[test] - fn bench_difference() { + fn it_reports_differences() { let mut bencher = Bencher::new(); bencher.bench("lol", || 3*4); bencher.bench("lol2", || 35*4); bencher.compare(); } + + #[test] + fn it_prints_settings() { + let mut bencher = Bencher::new(); + bencher.print_settings(); + bencher.set_iterations(0); + bencher.print_settings(); + } }