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

Add hash_bytes benchmark #289

Merged
merged 4 commits into from
Nov 30, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 20 additions & 6 deletions risc0/zkvm/benches/guest_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,36 @@ pub fn bench(c: &mut Criterion) {
guest_iter(b, BenchmarkSpec::SimpleLoop)
});

let mut sha_group = c.benchmark_group("raw_sha");
sha_group
let mut hash_bytes_group = c.benchmark_group("hash_bytes");
hash_bytes_group
.sampling_mode(SamplingMode::Flat)
.measurement_time(Duration::new(20, 0));
for buf_bytes in [0u64, 64, 512, 2048, 8192] {
sha_group.throughput(Throughput::Bytes(buf_bytes));
sha_group.bench_function(BenchmarkId::from_parameter(buf_bytes), |b| {
hash_bytes_group.throughput(Throughput::Bytes(buf_bytes));
hash_bytes_group.bench_function(BenchmarkId::from_parameter(buf_bytes), |b| {
let buf: Vec<u8> = rand_buffer(buf_bytes as usize);
guest_iter(b, BenchmarkSpec::HashBytes { buf: buf.clone() })
});
}
hash_bytes_group.finish();

let mut hash_raw_words_group = c.benchmark_group("hash_raw_words");
hash_raw_words_group
.sampling_mode(SamplingMode::Flat)
.measurement_time(Duration::new(20, 0));
for buf_bytes in [0u64, 64, 512, 2048, 8192] {
hash_raw_words_group.throughput(Throughput::Bytes(buf_bytes));
hash_raw_words_group.bench_function(BenchmarkId::from_parameter(buf_bytes), |b| {
let buf: Vec<u32> = rand_buffer((buf_bytes / 4) as usize);
guest_iter(b, BenchmarkSpec::RawSha { buf: buf.clone() })
guest_iter(b, BenchmarkSpec::HashRawWords { buf: buf.clone() })
});
}
sha_group.finish();
hash_raw_words_group.finish();

let mut memset_group = c.benchmark_group("memset");
memset_group.sampling_mode(SamplingMode::Flat);
for buf_bytes in [32u64, 64, 128, 256, 512, 1024, 2048, 4096] {
memset_group.throughput(Throughput::Bytes(buf_bytes));
memset_group.bench_with_input(
BenchmarkId::new("memset", buf_bytes),
&buf_bytes,
Expand Down
5 changes: 4 additions & 1 deletion risc0/zkvm/methods/src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone)]
pub enum BenchmarkSpec {
SimpleLoop,
RawSha {
HashBytes {
buf: Vec<u8>,
},
HashRawWords {
buf: Vec<u32>,
},
Memcpy {
Expand Down
8 changes: 7 additions & 1 deletion risc0/zkvm/methods/std/src/bin/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ pub fn main() {
memory_barrier(&i);
}
}
BenchmarkSpec::RawSha { buf } => {
BenchmarkSpec::HashBytes { buf } => {
let sha = sha::Impl {};
for _ in 0..iters {
memory_barrier(&sha.hash_bytes(&buf));
}
}
BenchmarkSpec::HashRawWords { buf } => {
let sha = sha::Impl {};
for _ in 0..iters {
memory_barrier(&sha.hash_raw_words(&buf));
Expand Down