Fix rust benches to work with the new compute API (#194)

This commit is contained in:
George Kadianakis 2023-03-09 18:30:46 +02:00 committed by GitHub
parent fa851f1b2c
commit ef82131be6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -23,20 +23,6 @@ fn generate_random_blob(rng: &mut ThreadRng) -> Blob {
arr.into() arr.into()
} }
fn generate_random_commitment(rng: &mut ThreadRng, s: &KZGSettings) -> Bytes48 {
let blob = generate_random_blob(rng);
KZGCommitment::blob_to_kzg_commitment(blob, s)
.unwrap()
.to_bytes()
}
fn generate_random_proof(rng: &mut ThreadRng, s: &KZGSettings) -> Bytes48 {
let blob = generate_random_blob(rng);
KZGProof::compute_blob_kzg_proof(blob, s)
.unwrap()
.to_bytes()
}
pub fn criterion_benchmark(c: &mut Criterion) { pub fn criterion_benchmark(c: &mut Criterion) {
let max_count: usize = 64; let max_count: usize = 64;
let mut rng = rand::thread_rng(); let mut rng = rand::thread_rng();
@ -47,11 +33,22 @@ pub fn criterion_benchmark(c: &mut Criterion) {
let blobs: Vec<Blob> = (0..max_count) let blobs: Vec<Blob> = (0..max_count)
.map(|_| generate_random_blob(&mut rng)) .map(|_| generate_random_blob(&mut rng))
.collect(); .collect();
let commitments: Vec<Bytes48> = (0..max_count) let commitments: Vec<Bytes48> = blobs
.map(|_| generate_random_commitment(&mut rng, &kzg_settings)) .iter()
.map(|blob| {
KZGCommitment::blob_to_kzg_commitment(*blob, &kzg_settings)
.unwrap()
.to_bytes()
})
.collect(); .collect();
let proofs: Vec<Bytes48> = (0..max_count) let proofs: Vec<Bytes48> = blobs
.map(|_| generate_random_proof(&mut rng, &kzg_settings)) .iter()
.zip(commitments.iter())
.map(|(blob, commitment)| {
KZGProof::compute_blob_kzg_proof(*blob, *commitment, &kzg_settings)
.unwrap()
.to_bytes()
})
.collect(); .collect();
let fields: Vec<Bytes32> = (0..max_count) let fields: Vec<Bytes32> = (0..max_count)
.map(|_| generate_random_field_element(&mut rng)) .map(|_| generate_random_field_element(&mut rng))
@ -72,7 +69,13 @@ pub fn criterion_benchmark(c: &mut Criterion) {
}); });
c.bench_function("compute_blob_kzg_proof", |b| { c.bench_function("compute_blob_kzg_proof", |b| {
b.iter(|| KZGProof::compute_blob_kzg_proof(*blobs.first().unwrap(), &kzg_settings)) b.iter(|| {
KZGProof::compute_blob_kzg_proof(
*blobs.first().unwrap(),
*commitments.first().unwrap(),
&kzg_settings,
)
})
}); });
c.bench_function("verify_blob_kzg_proof", |b| { c.bench_function("verify_blob_kzg_proof", |b| {