Hash benchmarks (#295)

This commit is contained in:
Daniel Lubarov 2021-10-09 14:07:49 -07:00 committed by GitHub
parent c55181a4ea
commit dc600d5abf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 0 deletions

View File

@ -38,6 +38,10 @@ harness = false
name = "ffts"
harness = false
[[bench]]
name = "hashing"
harness = false
[[bench]]
name = "transpose"
harness = false

View File

@ -2,6 +2,7 @@
use criterion::{criterion_group, criterion_main, BatchSize, Criterion};
use plonky2::field::crandall_field::CrandallField;
use plonky2::field::extension_field::quartic::QuarticExtension;
use plonky2::field::field_types::Field;
use plonky2::field::goldilocks_field::GoldilocksField;
use tynm::type_name;

39
benches/hashing.rs Normal file
View File

@ -0,0 +1,39 @@
#![feature(destructuring_assignment)]
#![feature(generic_const_exprs)]
use criterion::{criterion_group, criterion_main, BatchSize, Criterion};
use plonky2::field::goldilocks_field::GoldilocksField;
use plonky2::hash::gmimc::GMiMC;
use plonky2::hash::poseidon::Poseidon;
use tynm::type_name;
pub(crate) fn bench_gmimc<F: GMiMC<WIDTH>, const WIDTH: usize>(c: &mut Criterion) {
c.bench_function(&format!("gmimc<{}, {}>", type_name::<F>(), WIDTH), |b| {
b.iter_batched(
|| F::rand_arr::<WIDTH>(),
|mut state| F::gmimc_permute(state),
BatchSize::SmallInput,
)
});
}
pub(crate) fn bench_poseidon<F: Poseidon<WIDTH>, const WIDTH: usize>(c: &mut Criterion)
where
[(); WIDTH - 1]: ,
{
c.bench_function(&format!("poseidon<{}, {}>", type_name::<F>(), WIDTH), |b| {
b.iter_batched(
|| F::rand_arr::<WIDTH>(),
|mut state| F::poseidon(state),
BatchSize::SmallInput,
)
});
}
fn criterion_benchmark(c: &mut Criterion) {
bench_gmimc::<GoldilocksField, 12>(c);
bench_poseidon::<GoldilocksField, 12>(c);
}
criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);