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

add FnTimed type alias

parent cd862c1b
Branches
No related tags found
No related merge requests found
Pipeline #9115 passed
......@@ -9,6 +9,8 @@ use std::{
use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
type FnTimed<T> = Box<dyn Fn() -> TimeWithValue<T>>;
#[derive(Debug, Clone)]
/// hold information about the benchmark to run
pub struct Bencher {
......@@ -113,10 +115,7 @@ impl Bencher {
/// - the measurements will be printed to STDOUT or to file as JSON
/// - the result of the last run will be returned
#[allow(clippy::type_complexity)]
pub fn bench_multiple_and_return<O>(
&self,
benches: Vec<(String, Box<dyn Fn() -> TimeWithValue<O>>)>,
) -> Option<O> {
pub fn bench_multiple_and_return<O>(&self, benches: Vec<(String, FnTimed<O>)>) -> Option<O> {
let style = ProgressStyle::with_template(
"[{elapsed_precise}] {bar:40.cyan/blue} {pos:>10}/{len:10} {msg}",
)
......@@ -157,21 +156,17 @@ impl Bencher {
/// see [`Self::bench_multiple_and_return`]
#[allow(clippy::type_complexity)]
pub fn bench_multiple<O>(&self, benches: Vec<(String, Box<dyn Fn() -> TimeWithValue<O>>)>) {
pub fn bench_multiple<O>(&self, benches: Vec<(String, FnTimed<O>)>) {
self.bench_multiple_and_return(benches);
}
/// see [`Self::bench_multiple_and_return`]
pub fn bench_and_return<O>(
&self,
label: impl ToString,
f: Box<dyn Fn() -> TimeWithValue<O>>,
) -> Option<O> {
pub fn bench_and_return<O>(&self, label: impl ToString, f: FnTimed<O>) -> Option<O> {
self.bench_multiple_and_return(vec![(label.to_string(), f)])
}
/// see [`Self::bench_multiple_and_return`]
pub fn bench<O>(&self, label: impl ToString, f: Box<dyn Fn() -> TimeWithValue<O>>) {
pub fn bench<O>(&self, label: impl ToString, f: FnTimed<O>) {
self.bench_multiple_and_return(vec![(label.to_string(), f)]);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment