mirror of
https://github.com/arnaucube/hyperplonk.git
synced 2026-01-09 23:51:28 +01:00
benchmark code (#18)
This commit is contained in:
@@ -19,6 +19,12 @@ displaydoc = { version = "0.2.3", default-features = false }
|
|||||||
|
|
||||||
rayon = { version = "1.5.2", default-features = false, optional = true }
|
rayon = { version = "1.5.2", default-features = false, optional = true }
|
||||||
|
|
||||||
|
# Benchmarks
|
||||||
|
[[bench]]
|
||||||
|
name = "poly-iop-benches"
|
||||||
|
path = "benches/bench.rs"
|
||||||
|
harness = false
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
# default = [ "parallel", "print-trace" ]
|
# default = [ "parallel", "print-trace" ]
|
||||||
default = [ "parallel" ]
|
default = [ "parallel" ]
|
||||||
|
|||||||
119
poly-iop/benches/bench.rs
Normal file
119
poly-iop/benches/bench.rs
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
use std::time::Instant;
|
||||||
|
|
||||||
|
use ark_bls12_381::Fr;
|
||||||
|
use ark_std::test_rng;
|
||||||
|
use poly_iop::{PolyIOP, PolyIOPErrors, SumCheck, VirtualPolynomial, ZeroCheck};
|
||||||
|
|
||||||
|
fn main() -> Result<(), PolyIOPErrors> {
|
||||||
|
bench_sum_check()?;
|
||||||
|
println!("\n\n");
|
||||||
|
bench_zero_check()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn bench_sum_check() -> Result<(), PolyIOPErrors> {
|
||||||
|
let mut rng = test_rng();
|
||||||
|
for degree in 2..4 {
|
||||||
|
for nv in 4..25 {
|
||||||
|
let repetition = if nv < 10 {
|
||||||
|
100
|
||||||
|
} else if nv < 20 {
|
||||||
|
50
|
||||||
|
} else {
|
||||||
|
10
|
||||||
|
};
|
||||||
|
|
||||||
|
let (poly, asserted_sum) =
|
||||||
|
VirtualPolynomial::rand(nv, (degree, degree + 1), 2, &mut rng)?;
|
||||||
|
let poly_info = poly.domain_info.clone();
|
||||||
|
let proof = {
|
||||||
|
let start = Instant::now();
|
||||||
|
let mut transcript = <PolyIOP<Fr> as SumCheck<Fr>>::init_transcript();
|
||||||
|
let proof = <PolyIOP<Fr> as SumCheck<Fr>>::prove(&poly, &mut transcript)?;
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"sum check proving time for {} variables and {} degree: {} ns",
|
||||||
|
nv,
|
||||||
|
degree,
|
||||||
|
start.elapsed().as_nanos() / repetition as u128
|
||||||
|
);
|
||||||
|
proof
|
||||||
|
};
|
||||||
|
|
||||||
|
{
|
||||||
|
let start = Instant::now();
|
||||||
|
let mut transcript = <PolyIOP<Fr> as SumCheck<Fr>>::init_transcript();
|
||||||
|
let subclaim = <PolyIOP<Fr> as SumCheck<Fr>>::verify(
|
||||||
|
asserted_sum,
|
||||||
|
&proof,
|
||||||
|
&poly_info,
|
||||||
|
&mut transcript,
|
||||||
|
)?;
|
||||||
|
assert!(
|
||||||
|
poly.evaluate(&subclaim.point).unwrap() == subclaim.expected_evaluation,
|
||||||
|
"wrong subclaim"
|
||||||
|
);
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"sum check verification time for {} variables: {} ns",
|
||||||
|
nv,
|
||||||
|
start.elapsed().as_nanos() / repetition as u128
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("====================================");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn bench_zero_check() -> Result<(), PolyIOPErrors> {
|
||||||
|
let mut rng = test_rng();
|
||||||
|
for degree in 2..4 {
|
||||||
|
for nv in 4..20 {
|
||||||
|
let repetition = if nv < 10 {
|
||||||
|
100
|
||||||
|
} else if nv < 20 {
|
||||||
|
50
|
||||||
|
} else {
|
||||||
|
10
|
||||||
|
};
|
||||||
|
|
||||||
|
let poly = VirtualPolynomial::rand_zero(nv, (degree, degree + 1), 2, &mut rng)?;
|
||||||
|
let poly_info = poly.domain_info.clone();
|
||||||
|
let proof = {
|
||||||
|
let start = Instant::now();
|
||||||
|
let mut transcript = <PolyIOP<Fr> as ZeroCheck<Fr>>::init_transcript();
|
||||||
|
transcript.append_message(b"testing", b"initializing transcript for testing")?;
|
||||||
|
let proof = <PolyIOP<Fr> as ZeroCheck<Fr>>::prove(&poly, &mut transcript)?;
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"zero check proving time for {} variables and {} degree: {} ns",
|
||||||
|
nv,
|
||||||
|
degree,
|
||||||
|
start.elapsed().as_nanos() / repetition as u128
|
||||||
|
);
|
||||||
|
proof
|
||||||
|
};
|
||||||
|
|
||||||
|
{
|
||||||
|
let start = Instant::now();
|
||||||
|
let mut transcript = <PolyIOP<Fr> as ZeroCheck<Fr>>::init_transcript();
|
||||||
|
transcript.append_message(b"testing", b"initializing transcript for testing")?;
|
||||||
|
let subclaim =
|
||||||
|
<PolyIOP<Fr> as ZeroCheck<Fr>>::verify(&proof, &poly_info, &mut transcript)?.0;
|
||||||
|
assert!(
|
||||||
|
poly.evaluate(&subclaim.point)? == subclaim.expected_evaluation,
|
||||||
|
"wrong subclaim"
|
||||||
|
);
|
||||||
|
println!(
|
||||||
|
"zero check verification time for {} variables: {} ns",
|
||||||
|
nv,
|
||||||
|
start.elapsed().as_nanos() / repetition as u128
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("====================================");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
@@ -9,7 +9,10 @@ mod utils;
|
|||||||
mod virtual_poly;
|
mod virtual_poly;
|
||||||
mod zero_check;
|
mod zero_check;
|
||||||
|
|
||||||
|
pub use errors::PolyIOPErrors;
|
||||||
|
pub use sum_check::SumCheck;
|
||||||
pub use virtual_poly::VirtualPolynomial;
|
pub use virtual_poly::VirtualPolynomial;
|
||||||
|
pub use zero_check::ZeroCheck;
|
||||||
|
|
||||||
/// Struct for PolyIOP protocol.
|
/// Struct for PolyIOP protocol.
|
||||||
/// It is instantiated with
|
/// It is instantiated with
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ impl<F: PrimeField> IOPTranscript<F> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// append the message to the transcript
|
// append the message to the transcript
|
||||||
pub(crate) fn append_message(
|
pub fn append_message(
|
||||||
&mut self,
|
&mut self,
|
||||||
label: &'static [u8],
|
label: &'static [u8],
|
||||||
msg: &[u8],
|
msg: &[u8],
|
||||||
|
|||||||
@@ -6,3 +6,4 @@ export RUSTFLAGS="-C overflow-checks=on"
|
|||||||
cargo test --release -- -Zunstable-options --report-time
|
cargo test --release -- -Zunstable-options --report-time
|
||||||
cargo test --no-run --features=print-trace
|
cargo test --no-run --features=print-trace
|
||||||
cargo test --no-run --no-default-features
|
cargo test --no-run --no-default-features
|
||||||
|
cargo bench --no-run
|
||||||
Reference in New Issue
Block a user