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

allow easy adjustment of Fibonacci sequence benchmark #229

Merged
merged 1 commit into from
Sep 29, 2023
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
2 changes: 1 addition & 1 deletion triton-vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ name = "prove_halt"
harness = false

[[bench]]
name = "prove_fib_100"
name = "prove_fib"
harness = false

[[bench]]
Expand Down
79 changes: 79 additions & 0 deletions triton-vm/benches/prove_fib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
use criterion::criterion_group;
use criterion::criterion_main;
use criterion::BenchmarkId;
use criterion::Criterion;

use triton_vm::aet::AlgebraicExecutionTrace;
use triton_vm::example_programs::FIBONACCI_SEQUENCE;
use triton_vm::profiler::Report;
use triton_vm::profiler::TritonProfiler;
use triton_vm::proof::Claim;
use triton_vm::stark::Stark;
use triton_vm::stark::StarkHasher;
use triton_vm::PublicInput;
use triton_vm::StarkParameters;

const FIBONACCI_INDEX: u64 = 100;

/// cargo criterion --bench prove_fib
fn prove_fib(criterion: &mut Criterion) {
let (claim, aet) = trace_execution();
fib_benchmark_group(criterion, &claim, &aet);

let report = prover_timing_report(&claim, &aet);
println!("Writing report ...");
println!("{report}");
}

fn fib_benchmark_group(criterion: &mut Criterion, claim: &Claim, aet: &AlgebraicExecutionTrace) {
let bench_id_name = format!("ProveFib{FIBONACCI_INDEX}");
let bench_group_name = format!("prove_fib_{FIBONACCI_INDEX}");
let bench_id = BenchmarkId::new(bench_id_name, 0);
let mut group = criterion.benchmark_group(bench_group_name);

let parameters = StarkParameters::default();
group.bench_function(bench_id, |bencher| {
bencher.iter(|| Stark::prove(&parameters, claim, aet, &mut None))
});
group.finish();
}

fn prover_timing_report(claim: &Claim, aet: &AlgebraicExecutionTrace) -> Report {
let profile_name = format!("Prove Fibonacci {FIBONACCI_INDEX}");
let parameters = StarkParameters::default();
let mut profiler = Some(TritonProfiler::new(&profile_name));
let proof = Stark::prove(&parameters, claim, aet, &mut profiler);
let mut profiler = profiler.unwrap();
profiler.finish();

let padded_height = proof.padded_height().unwrap();
let fri = Stark::derive_fri(&parameters, padded_height);
profiler
.report()
.with_cycle_count(aet.processor_trace.nrows())
.with_padded_height(padded_height)
.with_fri_domain_len(fri.domain.length)
}

fn trace_execution() -> (Claim, AlgebraicExecutionTrace) {
let program = FIBONACCI_SEQUENCE.clone();
let public_input: PublicInput = vec![FIBONACCI_INDEX].into();
let (aet, output) = program
.trace_execution(public_input.clone(), [].into())
.unwrap();

let claim = Claim {
input: public_input.individual_tokens,
program_digest: program.hash::<StarkHasher>(),
output,
};
(claim, aet)
}

criterion_group! {
name = benches;
config = Criterion::default();
targets = prove_fib
}

criterion_main!(benches);
60 changes: 0 additions & 60 deletions triton-vm/benches/prove_fib_100.rs

This file was deleted.

Loading