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