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.

59 lines
1.8 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. use criterion::{criterion_group, criterion_main, Criterion};
  2. extern crate rand;
  3. #[macro_use]
  4. extern crate ff;
  5. use ff::*;
  6. extern crate num;
  7. extern crate num_bigint;
  8. use num_bigint::{BigInt, ToBigInt};
  9. use babyjubjub_rs::{utils, Point};
  10. fn criterion_benchmark(c: &mut Criterion) {
  11. let p: Point = Point {
  12. x: babyjubjub_rs::Fr::from_str(
  13. "17777552123799933955779906779655732241715742912184938656739573121738514868268",
  14. )
  15. .unwrap(),
  16. y: babyjubjub_rs::Fr::from_str(
  17. "2626589144620713026669568689430873010625803728049924121243784502389097019475",
  18. )
  19. .unwrap(),
  20. };
  21. let q = p.clone();
  22. let p_projective = p.projective();
  23. let q_projective = q.projective();
  24. c.bench_function("add", |b| b.iter(|| p_projective.add(&q_projective)));
  25. let r: BigInt = BigInt::parse_bytes(b"3", 10).unwrap();
  26. c.bench_function("mul_scalar_small", |b| b.iter(|| p.mul_scalar(&r)));
  27. let r: BigInt = BigInt::parse_bytes(
  28. b"2626589144620713026669568689430873010625803728049924121243784502389097019475",
  29. 10,
  30. )
  31. .unwrap();
  32. c.bench_function("mul_scalar", |b| b.iter(|| p.mul_scalar(&r)));
  33. c.bench_function("point compress", |b| b.iter(|| p.compress()));
  34. let p_comp = p.compress();
  35. c.bench_function("point decompress", |b| {
  36. b.iter(|| babyjubjub_rs::decompress_point(p_comp))
  37. });
  38. let sk = babyjubjub_rs::new_key();
  39. let pk = sk.public().unwrap();
  40. let msg = 5.to_bigint().unwrap();
  41. c.bench_function("sign_poseidon", |b| {
  42. b.iter(|| sk.sign_poseidon(msg.clone()))
  43. });
  44. let sig = sk.sign_poseidon(msg.clone()).unwrap();
  45. c.bench_function("verify_poseidon", |b| {
  46. b.iter(|| babyjubjub_rs::verify_poseidon(pk.clone(), sig.clone(), msg.clone()))
  47. });
  48. }
  49. criterion_group!(benches, criterion_benchmark);
  50. criterion_main!(benches);