Skip to content

Commit

Permalink
simple merkle benchmark (#527)
Browse files Browse the repository at this point in the history
<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/starkware-libs/stwo/527)
<!-- Reviewable:end -->
  • Loading branch information
spapinistarkware authored Apr 3, 2024
1 parent 14fa2ac commit 9298cc9
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ name = "matrix"
name = "merkle_bench"
harness = false

[[bench]]
name = "merkle"
harness = false

[[bench]]
name = "fri"
harness = false
Expand Down
40 changes: 40 additions & 0 deletions benches/merkle.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#![feature(iter_array_chunks)]

use criterion::Criterion;

#[cfg(target_arch = "x86_64")]
pub fn cpu_merkle(c: &mut criterion::Criterion) {
use itertools::Itertools;
use num_traits::Zero;
use stwo::commitment_scheme::ops::MerkleOps;
use stwo::core::backend::CPUBackend;
use stwo::core::fields::m31::BaseField;

const N_COLS: usize = 1 << 8;
const LOG_SIZE: u32 = 20;
let cols = (0..N_COLS)
.map(|_| {
(0..(1 << LOG_SIZE))
.map(|_| BaseField::zero())
.collect::<Vec<_>>()
})
.collect::<Vec<_>>();

let mut group = c.benchmark_group("merkle throughput");
group.throughput(criterion::Throughput::Elements((N_COLS << LOG_SIZE) as u64));
group.throughput(criterion::Throughput::Bytes(
(N_COLS << (LOG_SIZE + 2)) as u64,
));
group.bench_function("cpu merkle", |b| {
b.iter(|| {
CPUBackend::commit_on_layer(LOG_SIZE, None, &cols.iter().collect_vec());
})
});
}

#[cfg(target_arch = "x86_64")]
criterion::criterion_group!(
name=merkle;
config = Criterion::default().sample_size(10);
targets=cpu_merkle);
criterion::criterion_main!(merkle);

0 comments on commit 9298cc9

Please sign in to comment.