use criterion::{Criterion, criterion_group};
use qfall_math::{integer_mod_q::MatZq, rational::Q};
use qfall_tools::{
primitive::psf::{PSF, PSFGPV, PSFPerturbation},
sample::g_trapdoor::gadget_parameters::GadgetParameters,
};
fn bench_psf(c: &mut Criterion) {
let (n, q) = (8, 128);
let psf = PSFGPV {
gp: GadgetParameters::init_default(n, q),
s: Q::from(30) * Q::from(n).log(2).unwrap(),
};
let target = MatZq::sample_uniform(n, 1, q);
let (a, r) = psf.trap_gen();
c.bench_function("PSF GPV n=8", |b| b.iter(|| psf.samp_p(&a, &r, &target)));
}
fn bench_psf_perturbation(c: &mut Criterion) {
let (n, q) = (8, 128);
let psf = PSFPerturbation {
gp: GadgetParameters::init_default(n, q),
s: Q::from(30),
r: Q::from(n).log(2).unwrap(),
};
let target = MatZq::sample_uniform(n, 1, q);
let (a, r) = psf.trap_gen();
c.bench_function("PSF Perturbation n=8", |b| {
b.iter(|| psf.samp_p(&a, &r, &target))
});
}
fn bench_psf_perturbation_larger(c: &mut Criterion) {
let (n, q) = (64, 128);
let psf = PSFPerturbation {
gp: GadgetParameters::init_default(n, q),
s: Q::from(100),
r: Q::from(n).log(2).unwrap(),
};
let target = MatZq::sample_uniform(n, 1, q);
let (a, r) = psf.trap_gen();
c.bench_function("PSF Perturbation n=64", |b| {
b.iter(|| psf.samp_p(&a, &r, &target))
});
}
criterion_group!(
benches,
bench_psf,
bench_psf_perturbation,
bench_psf_perturbation_larger,
);