spdpf.rs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
  2. use dpf::spdpf::{DummySpDpf, HalfTreeSpDpf, SinglePointDpf};
  3. use utils::field::{Fp, FromHash};
  4. const LOG_DOMAIN_SIZES: [usize; 4] = [8, 12, 16, 20];
  5. fn bench_spdpf_keygen<SPDPF, F>(c: &mut Criterion, dpf_name: &str, field_name: &str)
  6. where
  7. SPDPF: SinglePointDpf<Value = F>,
  8. F: Copy + FromHash,
  9. {
  10. let mut group = c.benchmark_group(format!("{}-{}-keygen", dpf_name, field_name));
  11. let alpha = 42;
  12. let beta = F::hash_bytes(&[0x13, 0x37, 0x42, 0x47]);
  13. for log_domain_size in LOG_DOMAIN_SIZES.iter() {
  14. group.bench_with_input(
  15. BenchmarkId::from_parameter(log_domain_size),
  16. log_domain_size,
  17. |b, &log_domain_size| {
  18. b.iter(|| {
  19. let (_key_0, _key_1) = SPDPF::generate_keys(1 << log_domain_size, alpha, beta);
  20. });
  21. },
  22. );
  23. }
  24. group.finish();
  25. }
  26. fn bench_spdpf_evaluate_domain<SPDPF, F>(c: &mut Criterion, dpf_name: &str, field_name: &str)
  27. where
  28. SPDPF: SinglePointDpf<Value = F>,
  29. F: Copy + FromHash,
  30. {
  31. let mut group = c.benchmark_group(format!("{}-{}-evaluate_domain", dpf_name, field_name));
  32. let alpha = 42;
  33. let beta = F::hash_bytes(&[0x13, 0x37, 0x42, 0x47]);
  34. for log_domain_size in LOG_DOMAIN_SIZES.iter() {
  35. group.bench_with_input(
  36. BenchmarkId::from_parameter(log_domain_size),
  37. log_domain_size,
  38. |b, &log_domain_size| {
  39. let (key_0, _key_1) = SPDPF::generate_keys(1 << log_domain_size, alpha, beta);
  40. b.iter(|| {
  41. SPDPF::evaluate_domain(&key_0);
  42. });
  43. },
  44. );
  45. }
  46. group.finish();
  47. }
  48. fn bench_spdpf<SPDPF, F>(c: &mut Criterion, dpf_name: &str, field_name: &str)
  49. where
  50. SPDPF: SinglePointDpf<Value = F>,
  51. F: Copy + FromHash,
  52. {
  53. bench_spdpf_keygen::<SPDPF, F>(c, dpf_name, field_name);
  54. bench_spdpf_evaluate_domain::<SPDPF, F>(c, dpf_name, field_name);
  55. }
  56. fn bench_all_spdpf(c: &mut Criterion) {
  57. bench_spdpf::<DummySpDpf<Fp>, _>(c, "DummySpDpf", "Fp");
  58. bench_spdpf::<HalfTreeSpDpf<Fp>, _>(c, "HalfTreeSpDpf", "Fp");
  59. }
  60. criterion_group!(
  61. name = benches;
  62. config = Criterion::default().sample_size(10);
  63. targets = bench_all_spdpf
  64. );
  65. criterion_main!(benches);