Skip to content

Commit

Permalink
Benchmark runtime for prover only
Browse files Browse the repository at this point in the history
  • Loading branch information
jprider63 committed Feb 4, 2025
1 parent 71445d8 commit d567e70
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 1 deletion.
4 changes: 4 additions & 0 deletions examples/alloc/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
use std::time::Instant;

pub fn main() {
let (prove_alloc, verify_alloc) = guest::build_alloc();

let now = Instant::now();
let (output, proof) = prove_alloc(41);
println!("Prover runtime: {} s", now.elapsed().as_secs_f64());
let is_valid = verify_alloc(proof);

println!("output: {:?}", output);
Expand Down
6 changes: 6 additions & 0 deletions examples/collatz/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
use std::time::Instant;

pub fn main() {
// Prove/verify convergence for a single number:
let (prove_collatz_single, verify_collatz_single) = guest::build_collatz_convergence();

let now = Instant::now();
let (output, proof) = prove_collatz_single(19);
println!("Prover runtime: {} s", now.elapsed().as_secs_f64());
let is_valid = verify_collatz_single(proof);

println!("output: {}", output);
Expand All @@ -14,7 +18,9 @@ pub fn main() {

// https://www.reddit.com/r/compsci/comments/gk9x6g/collatz_conjecture_news_recently_i_managed_to/
let start: u128 = 1 << 68;
let now = Instant::now();
let (output, proof) = prove_collatz_convergence(start, start + 100);
println!("Prover runtime: {} s", now.elapsed().as_secs_f64());
let is_valid = verify_collatz_convergence(proof);

println!("output: {}", output);
Expand Down
4 changes: 4 additions & 0 deletions examples/fibonacci/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
use std::time::Instant;

pub fn main() {
let (prove_fib, verify_fib) = guest::build_fib();
let program_summary = guest::analyze_fib(10);
program_summary
.write_to_file("fib_10.txt".into())
.expect("should write");

let now = Instant::now();
let (output, proof) = prove_fib(50);
println!("Prover runtime: {} s", now.elapsed().as_secs_f64());
let is_valid = verify_fib(proof);

println!("output: {}", output);
Expand Down
4 changes: 4 additions & 0 deletions examples/memory-ops/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
use std::time::Instant;

pub fn main() {
let (prove, verify) = guest::build_memory_ops();

let now = Instant::now();
let (output, proof) = prove();
println!("Prover runtime: {} s", now.elapsed().as_secs_f64());
let is_valid = verify(proof);

println!(
Expand Down
4 changes: 4 additions & 0 deletions examples/muldiv/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
use std::time::Instant;

pub fn main() {
let (prove, verify) = guest::build_muldiv();

let now = Instant::now();
let (output, proof) = prove(12031293, 17, 92);
println!("Prover runtime: {} s", now.elapsed().as_secs_f64());
let is_valid = verify(proof);

println!("output: {}", output);
Expand Down
2 changes: 2 additions & 0 deletions examples/multi-function/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ pub fn main() {
let (prove_add, verify_add) = guest::build_add();
let (prove_mul, verify_mul) = guest::build_mul();

let now = Instant::now();

Check failure on line 5 in examples/multi-function/src/main.rs

View workflow job for this annotation

GitHub Actions / clippy

failed to resolve: use of undeclared type `Instant`
let (output, proof) = prove_add(5, 10);
println!("Prover runtime: {} s", now.elapsed().as_secs_f64());
let is_valid = verify_add(proof);

println!("add output: {}", output);
Expand Down
3 changes: 3 additions & 0 deletions examples/overflow/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::any::Any;
use std::panic;
use std::time::Instant;

pub fn main() {
let (prove_overflow_stack, _) = guest::build_overflow_stack();
Expand All @@ -24,7 +25,9 @@ pub fn main() {
let (prove_allocate_stack_with_increased_size, verfiy_allocate_stack_with_increased_size) =
guest::build_allocate_stack_with_increased_size();

let now = Instant::now();
let (output, proof) = prove_allocate_stack_with_increased_size();
println!("Prover runtime: {} s", now.elapsed().as_secs_f64());
let is_valid = verfiy_allocate_stack_with_increased_size(proof);

println!("output: {}", output);
Expand Down
2 changes: 1 addition & 1 deletion examples/run_benchmarks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ for i in "${!test_directories[@]}"; do
# MRS: 1964 KB
output=$(/usr/bin/time -f "wall: %E (HH:MM:SS)\nreal: %e s\nMRS: %M KB" cargo run --release -p "$file" 2>&1)
# Extract 'real' time value using awk
exec_time=$(echo "$output" | awk '/real:/ {print $2}') # in seconds
exec_time=$(echo "$output" | awk '/Prover runtime:/ {print $3}') # in seconds
# Extract 'MRS' value using awk
mem_used=$(echo "$output" | awk '/MRS:/ {print $2}') # in KB
echo "$output" # Print the output for debugging
Expand Down
4 changes: 4 additions & 0 deletions examples/sha2-chain/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
use std::time::Instant;

pub fn main() {
let (prove_sha2_chain, verify_sha2_chain) = guest::build_sha2_chain();

let input = [5u8; 32];
let iters = 100;
let native_output = guest::sha2_chain(input, iters);
let now = Instant::now();
let (output, proof) = prove_sha2_chain(input, iters);
println!("Prover runtime: {} s", now.elapsed().as_secs_f64());
let is_valid = verify_sha2_chain(proof);

assert_eq!(output, native_output, "output mismatch");
Expand Down
4 changes: 4 additions & 0 deletions examples/sha2-ex/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
use std::time::Instant;

pub fn main() {
let (prove_sha2, verify_sha2) = guest::build_sha2();

let input: &[u8] = &[5u8; 32];
let now = Instant::now();
let (output, proof) = prove_sha2(input);
println!("Prover runtime: {} s", now.elapsed().as_secs_f64());
let is_valid = verify_sha2(proof);

println!("output: {}", hex::encode(output));
Expand Down
4 changes: 4 additions & 0 deletions examples/sha3-chain/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use std::time::Instant;

pub fn main() {
let (prove_sha3_chain, verify_sha3_chain) = guest::build_sha3_chain();

let input = [5u8; 32];
let iters = 100;
let now = Instant::now();
let (output, proof) = prove_sha3_chain(input, iters);
println!("Prover runtime: {} s", now.elapsed().as_secs_f64());
let is_valid = verify_sha3_chain(proof);

println!("output: {}", hex::encode(output));
Expand Down
4 changes: 4 additions & 0 deletions examples/sha3-ex/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
use std::time::Instant;

pub fn main() {
let (prove_sha3, verify_sha3) = guest::build_sha3();

let input: &[u8] = &[5u8; 32];
let now = Instant::now();
let (output, proof) = prove_sha3(input);
println!("Prover runtime: {} s", now.elapsed().as_secs_f64());
let is_valid = verify_sha3(proof);

println!("output: {}", hex::encode(output));
Expand Down
4 changes: 4 additions & 0 deletions examples/stdlib/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::time::Instant;

pub fn main() {
let (prove, verify) = guest::build_int_to_string();

Expand All @@ -9,7 +11,9 @@ pub fn main() {

let (prove, verify) = guest::build_string_concat();

let now = Instant::now();
let (output, proof) = prove(20);
println!("Prover runtime: {} s", now.elapsed().as_secs_f64());
let is_valid = verify(proof);

println!("string concat output: {:?}", output);
Expand Down

0 comments on commit d567e70

Please sign in to comment.