ntt.rs 951 B

123456789101112131415161718192021222324252627
  1. use criterion::{black_box, criterion_group, criterion_main, Criterion};
  2. use rand::Rng;
  3. use spiral_rs::aligned_memory::*;
  4. use spiral_rs::ntt::*;
  5. use spiral_rs::util::*;
  6. fn criterion_benchmark(c: &mut Criterion) {
  7. let params = get_test_params();
  8. let mut v1 = AlignedMemory64::new(params.crt_count * params.poly_len);
  9. let mut rng = rand::thread_rng();
  10. for i in 0..params.crt_count {
  11. for j in 0..params.poly_len {
  12. let idx = calc_index(&[i, j], &[params.crt_count, params.poly_len]);
  13. let val: u64 = rng.gen();
  14. v1[idx] = val % params.moduli[i];
  15. }
  16. }
  17. c.bench_function("nttf 2048", |b| {
  18. b.iter(|| ntt_forward(black_box(&params), black_box(v1.as_mut_slice())))
  19. });
  20. c.bench_function("ntti 2048", |b| {
  21. b.iter(|| ntt_inverse(black_box(&params), black_box(v1.as_mut_slice())))
  22. });
  23. }
  24. criterion_group!(benches, criterion_benchmark);
  25. criterion_main!(benches);