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.

57 lines
1.5 KiB

5 years ago
5 years ago
5 years ago
  1. use rand;
  2. #[macro_use]
  3. extern crate criterion;
  4. use algebra::{edwards_bls12::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 PedersenWindow 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. PedersenCommitment::<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 = PedersenCommitment::<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 = PedersenRandomness::rand(rng);
  29. PedersenCommitment::<Edwards, CommWindow>::commit(
  30. &parameters,
  31. &input,
  32. &commitment_randomness,
  33. )
  34. .unwrap();
  35. })
  36. });
  37. }
  38. criterion_group! {
  39. name = comm_setup;
  40. config = Criterion::default().sample_size(10);
  41. targets = pedersen_comm_setup
  42. }
  43. criterion_group! {
  44. name = comm_eval;
  45. config = Criterion::default().sample_size(10);
  46. targets = pedersen_comm_eval
  47. }
  48. criterion_main!(comm_setup, comm_eval);