Skip to content
Snippets Groups Projects
Unverified Commit 614b2a05 authored by STEVAN Antoine's avatar STEVAN Antoine :crab:
Browse files

don't require Bencher to be mutable in `bench`

parent dac52145
No related branches found
No related tags found
No related merge requests found
......@@ -10,13 +10,13 @@ cargo add plnk --git https://gitlab.isae-supaero.fr/a.stevan/plnk --tag 0.2.0 #
```rust
use rand::Rng;
fn arithmetic(b: &mut plnk::Bencher) {
fn arithmetic(b: &plnk::Bencher) {
plnk::bench(b, "addition", || plnk::timeit(|| 1 + 2));
plnk::bench(b, "substraction", || plnk::timeit(|| 1 - 2));
plnk::bench(b, "multiplication", || plnk::timeit(|| 2 * 3));
}
fn random(b: &mut plnk::Bencher) {
fn random(b: &plnk::Bencher) {
let mut rng = rand::thread_rng();
plnk::bench(b, "sampling", || plnk::timeit(|| rng.gen::<u128>()));
}
......@@ -25,8 +25,8 @@ fn main() {
const NB_MEASUREMENTS: usize = 10;
let bencher = plnk::Bencher::new(NB_MEASUREMENTS);
arithmetic(&mut bencher.with_name("arithmetic"));
random(&mut bencher.with_name("random"));
arithmetic(&bencher.with_name("arithmetic"));
random(&bencher.with_name("random"));
}
```
......
use rand::Rng;
fn arithmetic(b: &mut plnk::Bencher) {
fn arithmetic(b: &plnk::Bencher) {
plnk::bench(b, "addition", || plnk::timeit(|| 1 + 2));
plnk::bench(b, "substraction", || plnk::timeit(|| 1 - 2));
plnk::bench(b, "multiplication", || plnk::timeit(|| 2 * 3));
}
fn random(b: &mut plnk::Bencher) {
fn random(b: &plnk::Bencher) {
let mut rng = rand::thread_rng();
plnk::bench(b, "sampling", || plnk::timeit(|| rng.gen::<u128>()));
}
......@@ -15,6 +15,6 @@ fn main() {
const NB_MEASUREMENTS: usize = 10;
let bencher = plnk::Bencher::new(NB_MEASUREMENTS);
arithmetic(&mut bencher.with_name("arithmetic"));
random(&mut bencher.with_name("random"));
arithmetic(&bencher.with_name("arithmetic"));
random(&bencher.with_name("random"));
}
fn capture(b: &mut plnk::Bencher) {
fn capture(b: &plnk::Bencher) {
let outer = 10;
plnk::bench(b, "dummy", || {
let inner = outer;
......@@ -10,5 +10,5 @@ fn main() {
const NB_MEASUREMENTS: usize = 10;
let bencher = plnk::Bencher::new(NB_MEASUREMENTS);
capture(&mut bencher.with_name("capture"));
capture(&bencher.with_name("capture"));
}
......@@ -33,7 +33,7 @@ impl Bencher {
/// same bencher
/// - thing: the piece of code to run and measure
/// - the measurements will be printed to STDOUT as JSON
pub fn bench<F>(b: &mut Bencher, label: &str, mut thing: F)
pub fn bench<F>(b: &Bencher, label: &str, mut thing: F)
where
F: FnMut() -> Duration,
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment