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.

50 lines
1.3 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;
  5. use criterion::Criterion;
  6. use crypto_primitives::crh::{pedersen::*, FixedLengthCRH};
  7. #[derive(Clone, PartialEq, Eq, Hash)]
  8. pub struct HashWindow;
  9. impl PedersenWindow for HashWindow {
  10. const WINDOW_SIZE: usize = 250;
  11. const NUM_WINDOWS: usize = 8;
  12. }
  13. fn pedersen_crh_setup(c: &mut Criterion) {
  14. c.bench_function("Pedersen CRH Setup", move |b| {
  15. b.iter(|| {
  16. let mut rng = &mut rand::thread_rng();
  17. PedersenCRH::<Edwards, HashWindow>::setup(&mut rng).unwrap()
  18. })
  19. });
  20. }
  21. fn pedersen_crh_eval(c: &mut Criterion) {
  22. let mut rng = &mut rand::thread_rng();
  23. let parameters = PedersenCRH::<Edwards, HashWindow>::setup(&mut rng).unwrap();
  24. let input = vec![5u8; 128];
  25. c.bench_function("Pedersen CRH Eval", move |b| {
  26. b.iter(|| {
  27. PedersenCRH::<Edwards, HashWindow>::evaluate(&parameters, &input).unwrap();
  28. })
  29. });
  30. }
  31. criterion_group! {
  32. name = crh_setup;
  33. config = Criterion::default().sample_size(10);
  34. targets = pedersen_crh_setup
  35. }
  36. criterion_group! {
  37. name = crh_eval;
  38. config = Criterion::default().sample_size(10);
  39. targets = pedersen_crh_eval
  40. }
  41. criterion_main!(crh_setup, crh_eval);