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

add closure!

parent d011b9ee
Branches
No related tags found
No related merge requests found
Pipeline #9101 failed
...@@ -5,27 +5,27 @@ fn arithmetic(b: &plnk::Bencher) { ...@@ -5,27 +5,27 @@ fn arithmetic(b: &plnk::Bencher) {
let res = b.bench_multiple(vec![ let res = b.bench_multiple(vec![
( (
plnk::label! { operation: "addition" }.to_string(), plnk::label! { operation: "addition" }.to_string(),
Box::new(|| { plnk::closure! {
let a = rand::thread_rng().gen::<u128>(); let a = rand::thread_rng().gen::<u128>();
let b = rand::thread_rng().gen::<u128>(); let b = rand::thread_rng().gen::<u128>();
plnk::timeit(|| a + b) plnk::timeit(|| a + b)
}), },
), ),
( (
plnk::label! { operation: "subtraction" }.to_string(), plnk::label! { operation: "subtraction" }.to_string(),
Box::new(|| { plnk::closure! {
let a = rand::thread_rng().gen::<u128>(); let a = rand::thread_rng().gen::<u128>();
let b = rand::thread_rng().gen::<u128>(); let b = rand::thread_rng().gen::<u128>();
plnk::timeit(|| a - b) plnk::timeit(|| a - b)
}), },
), ),
( (
plnk::label! { operation: "multiplication" }.to_string(), plnk::label! { operation: "multiplication" }.to_string(),
Box::new(|| { plnk::closure! {
let a = rand::thread_rng().gen::<u128>(); let a = rand::thread_rng().gen::<u128>();
let b = rand::thread_rng().gen::<u128>(); let b = rand::thread_rng().gen::<u128>();
plnk::timeit(|| a * b) plnk::timeit(|| a * b)
}), },
), ),
]); ]);
...@@ -35,7 +35,7 @@ fn arithmetic(b: &plnk::Bencher) { ...@@ -35,7 +35,7 @@ fn arithmetic(b: &plnk::Bencher) {
fn random(b: &plnk::Bencher) { fn random(b: &plnk::Bencher) {
b.bench( b.bench(
plnk::label! { operation: "sampling" }, plnk::label! { operation: "sampling" },
Box::new(|| plnk::timeit(|| rand::thread_rng().gen::<u128>())), plnk::closure! { plnk::timeit(|| rand::thread_rng().gen::<u128>())},
); );
} }
......
...@@ -161,6 +161,13 @@ impl Bencher { ...@@ -161,6 +161,13 @@ impl Bencher {
} }
} }
#[macro_export]
macro_rules! closure {
($( $body:stmt );* $(;)?) => {
Box::new(move || { $( $body )* })
};
}
#[macro_export] #[macro_export]
macro_rules! label { macro_rules! label {
( $( $key:ident : $value:expr ),* $(,)? ) => {{ ( $( $key:ident : $value:expr ),* $(,)? ) => {{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment