You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.5 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. use rand;
  2. #[macro_use]
  3. extern crate criterion;
  4. use algebra::{ed_on_bls12_377::EdwardsProjective as Edwards, UniformRand};
  5. use criterion::Criterion;
  6. use crypto_primitives::commitment::{pedersen::*, CommitmentScheme};
  7. #[derive(Clone, PartialEq, Eq, Hash)]
  8. pub struct CommWindow;
  9. impl Window for CommWindow {
  10. const WINDOW_SIZE: usize = 250;
  11. const NUM_WINDOWS: usize = 8;
  12. }
  13. fn pedersen_comm_setup(c: &mut Criterion) {
  14. c.bench_function("Pedersen Commitment Setup", move |b| {
  15. b.iter(|| {
  16. let mut rng = &mut rand::thread_rng();
  17. Commitment::<Edwards, CommWindow>::setup(&mut rng).unwrap()
  18. })
  19. });
  20. }
  21. fn pedersen_comm_eval(c: &mut Criterion) {
  22. let mut rng = &mut rand::thread_rng();
  23. let parameters = Commitment::<Edwards, CommWindow>::setup(&mut rng).unwrap();
  24. let input = vec![5u8; 128];
  25. c.bench_function("Pedersen Commitment Eval", move |b| {
  26. b.iter(|| {
  27. let rng = &mut rand::thread_rng();
  28. let commitment_randomness = Randomness::rand(rng);
  29. Commitment::<Edwards, CommWindow>::commit(&parameters, &input, &commitment_randomness)
  30. .unwrap()
  31. })
  32. });
  33. }
  34. criterion_group! {
  35. name = comm_setup;
  36. config = Criterion::default().sample_size(10);
  37. targets = pedersen_comm_setup
  38. }
  39. criterion_group! {
  40. name = comm_eval;
  41. config = Criterion::default().sample_size(10);
  42. targets = pedersen_comm_eval
  43. }
  44. criterion_main!(comm_setup, comm_eval);