Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simple merkle benchmark #527

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Loading