use criterion::*;
use qfall_math::integer_mod_q::MatZq;
use std::{fs::File, io::Read};
pub fn bench_solve(c: &mut Criterion) {
let mut matrix = String::new();
let mut f_matrix = File::open("benches/matrix.txt").expect("Unable to open file");
f_matrix
.read_to_string(&mut matrix)
.expect("Unable to read string");
let matrix: MatZq = serde_json::from_str(&matrix).unwrap();
let mut target = String::new();
let mut f_target = File::open("benches/target.txt").expect("Unable to open file");
f_target
.read_to_string(&mut target)
.expect("Unable to read string");
let target: MatZq = serde_json::from_str(&target).unwrap();
c.bench_function("Solve 100x200 mod 4096", |b| {
b.iter(|| matrix.solve_gaussian_elimination(&target))
});
}
pub fn bench_inverse(c: &mut Criterion) {
let n = 300;
let q = 7;
c.bench_function("Inverse Matrix", |b| {
b.iter_batched(
|| {
let mut matrix = MatZq::sample_uniform(n, n, q);
while matrix.get_representative_least_absolute_residue().rank() < n {
matrix = MatZq::sample_uniform(n, n, q);
}
matrix
},
|matrix| matrix.inverse(),
BatchSize::SmallInput,
);
});
}
criterion_group!(benches, bench_solve, bench_inverse);