A couple field benchmarks (#161)

This commit is contained in:
Daniel Lubarov 2021-08-08 09:14:50 -07:00 committed by GitHub
parent 97c2b6b9a2
commit cc6c365176
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 0 deletions

View File

@ -24,6 +24,13 @@ anyhow = "1.0.40"
serde = { version = "1.0", features = ["derive"] }
serde_cbor = "0.11.1"
[dev-dependencies]
criterion = "0.3.5"
[[bench]]
name = "field_arithmetic"
harness = false
[profile.release]
opt-level = 3
#lto = "fat"

View File

@ -0,0 +1,28 @@
use std::any::type_name;
use criterion::{criterion_group, criterion_main, BatchSize, Criterion};
use plonky2::field::crandall_field::CrandallField;
use plonky2::field::extension_field::quartic::QuarticCrandallField;
use plonky2::field::field_types::Field;
pub(crate) fn bench_field<F: Field>(c: &mut Criterion) {
c.bench_function(&format!("{} mul", type_name::<F>()), |b| {
b.iter_batched(
|| (F::rand(), F::rand()),
|(x, y)| x * y,
BatchSize::SmallInput,
)
});
c.bench_function(&format!("{} try_inverse", type_name::<F>()), |b| {
b.iter_batched(|| F::rand(), |x| x.try_inverse(), BatchSize::SmallInput)
});
}
fn criterion_benchmark(c: &mut Criterion) {
bench_field::<CrandallField>(c);
bench_field::<QuarticCrandallField>(c);
}
criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);