Skip to content
Snippets Groups Projects
Verified Commit 18c687f5 authored by STEVAN Antoine's avatar STEVAN Antoine :crab:
Browse files

allow bencher to be quiet

parent 864f391b
No related branches found
No related tags found
No related merge requests found
Pipeline #9079 passed
......@@ -4,12 +4,15 @@ use std::time::{Duration, Instant};
use indicatif::{ProgressBar, ProgressStyle};
#[derive(Debug, Clone)]
/// hold information about the benchmark to run
pub struct Bencher {
/// the number of times each bench should run, the higher this number the lower the variance
nb_measurements: usize,
/// the name of the benchmark
name: String,
quiet: bool,
}
impl Bencher {
......@@ -17,6 +20,7 @@ impl Bencher {
Self {
nb_measurements,
name: "".to_string(),
quiet: false,
}
}
......@@ -25,8 +29,23 @@ impl Bencher {
Self {
nb_measurements: self.nb_measurements,
name: name.to_string(),
quiet: self.quiet,
}
}
/// makes the bencher quiet
pub fn quiet(&self) -> Self {
let mut ret = self.clone();
ret.quiet = true;
ret
}
/// makes the bencher verbose
pub fn verbose(&self) -> Self {
let mut ret = self.clone();
ret.quiet = false;
ret
}
}
#[macro_export]
......@@ -50,7 +69,9 @@ pub fn bench<F>(b: &Bencher, label: &str, mut f: F)
where
F: FnMut() -> Duration,
{
eprintln!("bencher: {}, label: {}", b.name, label,);
if !b.quiet {
eprintln!("bencher: {}, label: {}", b.name, label);
}
let pb = ProgressBar::new(b.nb_measurements as u64)
.with_style(ProgressStyle::default_bar().progress_chars("#*-"));
......@@ -75,7 +96,9 @@ pub fn bench_and_return<F, O>(b: &Bencher, label: &str, mut f: F) -> Option<O>
where
F: FnMut() -> (Duration, O),
{
eprintln!("bencher: {}, label: {}", b.name, label,);
if !b.quiet {
eprintln!("bencher: {}, label: {}", b.name, label);
}
let pb = ProgressBar::new(b.nb_measurements as u64)
.with_style(ProgressStyle::default_bar().progress_chars("#*-"));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment