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
  1. use criterion::{criterion_group, criterion_main, Criterion};
  2. extern crate num;
  3. extern crate num_bigint;
  4. extern crate num_traits;
  5. use num_bigint::{BigInt, ToBigInt};
  6. use babyjubjub_rs::{utils, Point};
  7. fn criterion_benchmark(c: &mut Criterion) {
  8. let x: BigInt = BigInt::parse_bytes(
  9. b"17777552123799933955779906779655732241715742912184938656739573121738514868268",
  10. 10,
  11. )
  12. .unwrap();
  13. c.bench_function("modulus", |b| {
  14. b.iter(|| utils::modulus(&x, &babyjubjub_rs::Q))
  15. });
  16. let p: Point = Point {
  17. x: BigInt::parse_bytes(
  18. b"17777552123799933955779906779655732241715742912184938656739573121738514868268",
  19. 10,
  20. )
  21. .unwrap(),
  22. y: BigInt::parse_bytes(
  23. b"2626589144620713026669568689430873010625803728049924121243784502389097019475",
  24. 10,
  25. )
  26. .unwrap(),
  27. };
  28. let q = p.clone();
  29. c.bench_function("add", |b| b.iter(|| p.add(&q)));
  30. c.bench_function("mul_scalar_small", |b| {
  31. b.iter(|| p.mul_scalar(&3.to_bigint().unwrap()))
  32. });
  33. let r: BigInt = BigInt::parse_bytes(
  34. b"2626589144620713026669568689430873010625803728049924121243784502389097019475",
  35. 10,
  36. )
  37. .unwrap();
  38. c.bench_function("mul_scalar", |b| b.iter(|| p.mul_scalar(&r)));
  39. let sk = babyjubjub_rs::new_key();
  40. let pk = sk.public().unwrap();
  41. let msg = 5.to_bigint().unwrap();
  42. c.bench_function("sign_poseidon", |b| {
  43. b.iter(|| sk.sign_poseidon(msg.clone()))
  44. });
  45. let sig = sk.sign_poseidon(msg.clone()).unwrap();
  46. c.bench_function("verify_poseidon", |b| {
  47. b.iter(|| babyjubjub_rs::verify_poseidon(pk.clone(), sig.clone(), msg.clone()))
  48. });
  49. }
  50. criterion_group!(benches, criterion_benchmark);
  51. criterion_main!(benches);