arnaucube
arnaucube/poulpyPublic Self-hosted repository
poulpy/math/benches/ring_rns.rs
math/benches/ring_rns.rsRaw
 1use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
 2use math::ring::{Ring, RingRNS};
 3use math::ring::impl_u64::ring_rns::new_rings;
 4use math::poly::PolyRNS;
 5
 6fn div_floor_by_last_modulus_ntt(c: &mut Criterion) {
 7    fn runner(r: RingRNS<u64>) -> Box<dyn FnMut() + '_> {
 8        
 9        let a: PolyRNS<u64> = r.new_polyrns();
10        let mut b: PolyRNS<u64> = r.new_polyrns();
11        let mut c: PolyRNS<u64> = r.new_polyrns();
12
13        Box::new(move || {
14            r.div_floor_by_last_modulus_ntt(&a, &mut b, &mut c)
15        })
16    }
17
18    let mut b: criterion::BenchmarkGroup<'_, criterion::measurement::WallTime> = c.benchmark_group("div_floor_by_last_modulus_ntt");
19    for log_n in 11..18 {
20
21        let n = 1<<log_n;
22        let moduli: Vec<u64> = vec![0x1fffffffffe00001u64, 0x1fffffffffc80001u64, 0x1fffffffffb40001, 0x1fffffffff500001];
23        let rings: Vec<Ring<u64>> = new_rings(n, moduli);
24        let ring_rns: RingRNS<'_, u64> = RingRNS::new(&rings);
25
26        let runners = [
27            (format!("prime/n={}/level={}", n, ring_rns.level()), {
28                runner(ring_rns)
29            }),
30        ];
31
32        for (name, mut runner) in runners {
33            b.bench_with_input(name, &(), |b, _| b.iter(&mut runner));
34        }
35    }
36}
37
38criterion_group!(benches, div_floor_by_last_modulus_ntt);
39criterion_main!(benches);