server.rs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. use criterion::{black_box, criterion_group, criterion_main, Criterion};
  2. use pprof::criterion::{Output, PProfProfiler};
  3. use spiral_rs::client::*;
  4. use spiral_rs::poly::*;
  5. use spiral_rs::server::*;
  6. use spiral_rs::util::*;
  7. use std::time::Duration;
  8. fn criterion_benchmark(c: &mut Criterion) {
  9. let mut group = c.benchmark_group("sample-size");
  10. group
  11. .sample_size(10)
  12. .measurement_time(Duration::from_secs(30));
  13. let params = get_expansion_testing_params();
  14. let v_neg1 = params.get_v_neg1();
  15. let mut seeded_rng = get_seeded_rng();
  16. let mut client = Client::init(&params, &mut seeded_rng);
  17. let public_params = client.generate_keys();
  18. let mut v = Vec::new();
  19. for _ in 0..params.poly_len {
  20. v.push(PolyMatrixNTT::zero(&params, 2, 1));
  21. }
  22. let scale_k = params.modulus / params.pt_modulus;
  23. let mut sigma = PolyMatrixRaw::zero(&params, 1, 1);
  24. sigma.data[7] = scale_k;
  25. v[0] = client.encrypt_matrix_reg(&sigma.ntt());
  26. let v_w_left = public_params.v_expansion_left.unwrap();
  27. let v_w_right = public_params.v_expansion_right.unwrap();
  28. // note: the benchmark on AVX2 is 545ms for the c++ impl
  29. group.bench_function("coeff_exp", |b| {
  30. b.iter(|| {
  31. coefficient_expansion(
  32. black_box(&mut v),
  33. black_box(client.g),
  34. black_box(client.stop_round),
  35. black_box(&params),
  36. black_box(&v_w_left),
  37. black_box(&v_w_right),
  38. black_box(&v_neg1),
  39. black_box(params.t_gsw * params.db_dim_2),
  40. )
  41. });
  42. });
  43. group.finish();
  44. }
  45. // criterion_group!(benches, criterion_benchmark);
  46. criterion_group! {
  47. name = benches;
  48. config = Criterion::default().with_profiler(PProfProfiler::new(100, Output::Flamegraph(None)));
  49. targets = criterion_benchmark
  50. }
  51. criterion_main!(benches);