From dc600d5abf72e85b09e8f443f0cc027488104135 Mon Sep 17 00:00:00 2001 From: Daniel Lubarov Date: Sat, 9 Oct 2021 14:07:49 -0700 Subject: [PATCH] Hash benchmarks (#295) --- Cargo.toml | 4 ++++ benches/field_arithmetic.rs | 1 + benches/hashing.rs | 39 +++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 benches/hashing.rs diff --git a/Cargo.toml b/Cargo.toml index 11aa6e40..4211830f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,6 +38,10 @@ harness = false name = "ffts" harness = false +[[bench]] +name = "hashing" +harness = false + [[bench]] name = "transpose" harness = false diff --git a/benches/field_arithmetic.rs b/benches/field_arithmetic.rs index d3ebc57c..f685465a 100644 --- a/benches/field_arithmetic.rs +++ b/benches/field_arithmetic.rs @@ -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; diff --git a/benches/hashing.rs b/benches/hashing.rs new file mode 100644 index 00000000..2eb2aa23 --- /dev/null +++ b/benches/hashing.rs @@ -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, const WIDTH: usize>(c: &mut Criterion) { + c.bench_function(&format!("gmimc<{}, {}>", type_name::(), WIDTH), |b| { + b.iter_batched( + || F::rand_arr::(), + |mut state| F::gmimc_permute(state), + BatchSize::SmallInput, + ) + }); +} + +pub(crate) fn bench_poseidon, const WIDTH: usize>(c: &mut Criterion) +where + [(); WIDTH - 1]: , +{ + c.bench_function(&format!("poseidon<{}, {}>", type_name::(), WIDTH), |b| { + b.iter_batched( + || F::rand_arr::(), + |mut state| F::poseidon(state), + BatchSize::SmallInput, + ) + }); +} + +fn criterion_benchmark(c: &mut Criterion) { + bench_gmimc::(c); + bench_poseidon::(c); +} + +criterion_group!(benches, criterion_benchmark); +criterion_main!(benches);