Skip to content

Commit

Permalink
Add criterion harness for internal stream measurements
Browse files Browse the repository at this point in the history
  • Loading branch information
imDema committed Jan 19, 2024
1 parent 2221ae4 commit c9407cf
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions benches/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,45 @@ pub fn remote_loopback_deploy(
.unwrap_or_else(|e| panic!("Remote worker for host {host_id} crashed: {e:?}"));
}
}

pub struct NoirBenchBuilder<F, G, R>
where
F: Fn() -> StreamEnvironment,
G: Fn(&mut StreamEnvironment) -> R,
{
make_env: F,
make_network: G,
_result: PhantomData<R>,
}

impl<F, G, R> NoirBenchBuilder<F, G, R>
where
F: Fn() -> StreamEnvironment,
G: Fn(&mut StreamEnvironment) -> R,
{
pub fn new(make_env: F, make_network: G) -> Self {
Self {
make_env,
make_network,
_result: Default::default(),
}
}

pub fn bench(&self, n: u64) -> Duration {
let mut time = Duration::default();
for _ in 0..n {
let mut env = (self.make_env)();
let _result = (self.make_network)(&mut env);
let start = Instant::now();
env.execute_blocking();
time += start.elapsed();
black_box(_result);
}
time
}
}

pub fn noir_bench_default(b: &mut Bencher, logic: impl Fn(&mut StreamEnvironment)) {
let builder = NoirBenchBuilder::new(StreamEnvironment::default, logic);
b.iter_custom(|n| builder.bench(n));
}

0 comments on commit c9407cf

Please sign in to comment.