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

pass progress bar to benchmarking closure

parent 1ff7b083
Branches main
No related tags found
No related merge requests found
Pipeline #9238 passed
......@@ -38,7 +38,7 @@ fn arithmetic(b: &plnk::Bencher) {
fn random(b: &plnk::Bencher) {
b.bench(
plnk::label! { operation: "sampling" },
plnk::closure! { plnk::timeit(|| rand::thread_rng().gen::<u128>())},
plnk::closure! { plnk::timeit(|| rand::thread_rng().gen::<u128>()) },
);
}
......
......@@ -9,7 +9,7 @@ use std::{
use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
pub type FnTimed<T> = Box<dyn Fn() -> TimeWithValue<T>>;
pub type FnTimed<T> = Box<dyn Fn(ProgressBar) -> TimeWithValue<T>>;
pub struct LabeledFnTimed<T> {
pub label: String,
......@@ -147,7 +147,7 @@ impl Bencher {
let mut times = vec![];
for _ in 0..self.nb_measurements {
let TimeWithValue { t, v } = func();
let TimeWithValue { t, v } = func(pb.clone());
res = Some(v);
times.push(t.as_nanos());
......@@ -190,8 +190,11 @@ impl Bencher {
#[macro_export]
macro_rules! closure {
($pb:ident, $( $body:stmt );* $(;)?) => {
Box::new(move |$pb: indicatif::ProgressBar| { $( $body )* }) as plnk::FnTimed<_>
};
($( $body:stmt );* $(;)?) => {
Box::new(move || { $( $body )* }) as plnk::FnTimed<_>
Box::new(move |_| { $( $body )* }) as plnk::FnTimed<_>
};
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment