Skip to content

Commit

Permalink
split benchmarks (risc0#1554)
Browse files Browse the repository at this point in the history
As of now, the benchmarks only display executor and total proving. This
change will split the benchmarks into these metrics: executor, prove
segment, lift, join, total composite, and total succinct. This will
allow us to better understand performance changes on a more granular
level.

Closes: risc0#1369
  • Loading branch information
SchmErik authored Mar 13, 2024
1 parent 1c6a24f commit 650bf4d
Showing 1 changed file with 80 additions and 8 deletions.
88 changes: 80 additions & 8 deletions risc0/zkvm/benches/fib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ fn setup(iterations: u32) -> ExecutorImpl<'static> {
}

enum Scope {
Prove,
Total,
ProveSegments,
Lift,
Join,
TotalComposite,
TotalSuccinct,
}

pub fn bench(c: &mut Criterion) {
Expand All @@ -53,16 +56,31 @@ pub fn bench(c: &mut Criterion) {
});
}

for scope in [Scope::Prove, Scope::Total] {
for scope in [
Scope::ProveSegments,
Scope::Lift,
Scope::Join,
Scope::TotalComposite,
Scope::TotalSuccinct,
] {
for iterations in [100, 1000, 10_000] {
let mut exec = setup(iterations);
let session = exec.run().unwrap();
let mut segment_receipts = vec![];
let mut lifted_receipts = vec![];
for segment in session.segments {
let segment_receipt = prover
.prove_segment(&ctx, &segment.resolve().unwrap())
.unwrap();
segment_receipts.push(segment_receipt.clone());
lifted_receipts.push(prover.lift(&segment_receipt).unwrap());
}
group.sample_size(10);
match scope {
Scope::Prove => {
let id = BenchmarkId::from_parameter(format!("{iterations}/prove"));
Scope::ProveSegments => {
let id = BenchmarkId::from_parameter(format!("{iterations}/prove segments"));
group.throughput(Throughput::Elements(session.total_cycles));
group.bench_with_input(id, &iterations, |b, &iterations| {
group.bench_with_input(id, &iterations, |b, _| {
b.iter_batched(
|| {
let mut exec = setup(iterations);
Expand All @@ -73,8 +91,44 @@ pub fn bench(c: &mut Criterion) {
)
});
}
Scope::Total => {
let id = BenchmarkId::from_parameter(format!("{iterations}/total"));
Scope::Lift => {
let id = BenchmarkId::from_parameter(format!("{iterations}/lift"));
group.throughput(Throughput::Elements(segment_receipts.len() as u64));
group.bench_with_input(id, &iterations, |b, _| {
b.iter_batched(
|| {},
|_| {
black_box({
for segment in &segment_receipts {
prover.lift(&segment).unwrap();
}
})
},
BatchSize::SmallInput,
)
});
}
Scope::Join => {
let id = BenchmarkId::from_parameter(format!("{iterations}/join"));
group.throughput(Throughput::Elements(lifted_receipts.len() as u64));
group.bench_with_input(id, &iterations, |b, _| {
b.iter_batched(
|| lifted_receipts.clone().into_iter(),
|mut lifted_receipts| {
black_box({
let mut join_receipt = lifted_receipts.next().unwrap();
for receipt in lifted_receipts {
join_receipt =
prover.join(&join_receipt, &receipt).unwrap();
}
})
},
BatchSize::SmallInput,
)
});
}
Scope::TotalComposite => {
let id = BenchmarkId::from_parameter(format!("{iterations}/total composite"));
group.throughput(Throughput::Elements(session.user_cycles));
group.bench_with_input(id, &iterations, |b, &iterations| {
b.iter_batched(
Expand All @@ -89,6 +143,24 @@ pub fn bench(c: &mut Criterion) {
)
});
}
Scope::TotalSuccinct => {
let id = BenchmarkId::from_parameter(format!("{iterations}/total succinct"));
group.throughput(Throughput::Elements(session.user_cycles));
group.bench_with_input(id, &iterations, |b, &iterations| {
b.iter_batched(
|| setup(iterations),
|mut exec| {
black_box({
let session = exec.run().unwrap();
let receipt = prover.prove_session(&ctx, &session).unwrap();
let composite_receipt = receipt.inner.composite().unwrap();
prover.compress(composite_receipt).unwrap();
})
},
BatchSize::SmallInput,
)
});
}
};
}
}
Expand Down

0 comments on commit 650bf4d

Please sign in to comment.