Skip to content

Commit

Permalink
add benches
Browse files Browse the repository at this point in the history
  • Loading branch information
Dustin-Ray committed Aug 23, 2024
1 parent beafedc commit 7ff1a05
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ sha3 = "0.10.6"
structopt = { version = "0.3.26", default-features = false }
env_logger = "0.11.5"
thiserror = "1.0.63"
criterion = "0.3"

[dev-dependencies]
debug_print = { version = "1.0.0" }
Expand All @@ -34,3 +35,8 @@ plonky2_crypto = { git = "https://github.com/Lagrange-Labs/plonky2-crypto", bran

[profile.dev]
opt-level = 3

[[bench]]
name = "hash_chain_bench"
path = "benches/hash_chain_benches.rs"
harness = false # Disable the default test harness for benchmarks
39 changes: 39 additions & 0 deletions benches/hash_chain_benches.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use hash_chain::HashChain;
use plonky2::{
field::goldilocks_field::GoldilocksField,
plonk::{
circuit_builder::CircuitBuilder,
circuit_data::CircuitConfig,
config::{GenericConfig, PoseidonGoldilocksConfig},
},
};

fn hash_chain_benchmark(c: &mut Criterion) {
const D: usize = 2;
type C = PoseidonGoldilocksConfig;
type F = <C as GenericConfig<D>>::F;

let config = CircuitConfig::standard_recursion_config();

let step_sizes = [2, 4, 8, 16, 32, 64]; // Example step sizes

for &steps in &step_sizes {
c.bench_function(&format!("hash_chain_{}_steps", steps), |b| {
b.iter(|| {
// Create the circuit inside the black_box to ensure it is evaluated
let mut circuit = black_box(CircuitBuilder::<F, D>::new(config.clone()));

let (_, _) = <CircuitBuilder<GoldilocksField, D> as HashChain<
GoldilocksField,
D,
C,
>>::build_hash_chain_circuit(&mut circuit, steps)
.unwrap();
});
});
}
}

criterion_group!(benches, hash_chain_benchmark);
criterion_main!(benches);
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ mod tests {
>>::build_hash_chain_circuit(&mut circuit, 2)
.unwrap();

let num_bytes = proof.to_bytes().len();

Check warning on line 479 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build_and_test

unused variable: `num_bytes`
let result =
<CircuitBuilder<GoldilocksField, D> as HashChain<GoldilocksField, D, C>>::verify(
proof,
Expand Down

0 comments on commit 7ff1a05

Please sign in to comment.