hyperplonk/arithmetic/benches/bench.rs
arithmetic/benches/bench.rsRaw
1// Copyright (c) 2023 Espresso Systems (espressosys.com)
2// This file is part of the HyperPlonk library.
3
4// You should have received a copy of the MIT License
5// along with the HyperPlonk library. If not, see <https://mit-license.org/>.
6
7#[macro_use]
8extern crate criterion;
9
10use arithmetic::fix_variables;
11use ark_bls12_381::Fr;
12use ark_ff::Field;
13use ark_poly::{DenseMultilinearExtension, MultilinearExtension};
14use ark_std::{ops::Range, test_rng};
15use criterion::{black_box, BenchmarkId, Criterion};
16
17const NUM_VARIABLES_RANGE: Range<usize> = 10..21;
18
19fn evaluation_op_bench<F: Field>(c: &mut Criterion) {
20 let mut rng = test_rng();
21 let mut group = c.benchmark_group("Evaluate");
22 for nv in NUM_VARIABLES_RANGE {
23 group.bench_with_input(BenchmarkId::new("evaluate native", nv), &nv, |b, &nv| {
24 let poly = DenseMultilinearExtension::<F>::rand(nv, &mut rng);
25 let point: Vec<_> = (0..nv).map(|_| F::rand(&mut rng)).collect();
26 b.iter(|| black_box(poly.evaluate(&point).unwrap()))
27 });
28
29 group.bench_with_input(BenchmarkId::new("evaluate optimized", nv), &nv, |b, &nv| {
30 let poly = DenseMultilinearExtension::<F>::rand(nv, &mut rng);
31 let point: Vec<_> = (0..nv).map(|_| F::rand(&mut rng)).collect();
32 b.iter(|| black_box(fix_variables(&poly, &point)))
33 });
34 }
35 group.finish();
36}
37
38fn bench_bls_381(c: &mut Criterion) {
39 evaluation_op_bench::<Fr>(c);
40}
41
42criterion_group!(benches, bench_bls_381);
43criterion_main!(benches);