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 rand;
 4#[macro_use]
 5extern crate ff;
 6use ff::*;
 7
 8extern crate num;
 9extern crate num_bigint;
10use num_bigint::BigInt;
11
12use babyjubjub_rs::{utils, Point};
13
14fn criterion_benchmark(c: &mut Criterion) {
15    // let x: BigInt = BigInt::parse_bytes(
16    //     b"17777552123799933955779906779655732241715742912184938656739573121738514868268",
17    //     10,
18    // )
19    // .unwrap();
20    // c.bench_function("modulus", |b| {
21    //     b.iter(|| utils::modulus(&x, &babyjubjub_rs::Q))
22    // });
23
24    let p: Point = Point {
25        x: babyjubjub_rs::Fr::from_str(
26            "17777552123799933955779906779655732241715742912184938656739573121738514868268",
27        )
28        .unwrap(),
29        y: babyjubjub_rs::Fr::from_str(
30            "2626589144620713026669568689430873010625803728049924121243784502389097019475",
31        )
32        .unwrap(),
33        z: babyjubjub_rs::Fr::one(),
34    };
35    let q = p.clone();
36
37    c.bench_function("add", |b| b.iter(|| p.add(&q)));
38    let r: BigInt = BigInt::parse_bytes(b"3", 10).unwrap();
39    c.bench_function("mul_scalar_small", |b| b.iter(|| p.mul_scalar(&r)));
40    let r: BigInt = BigInt::parse_bytes(
41        b"2626589144620713026669568689430873010625803728049924121243784502389097019475",
42        10,
43    )
44    .unwrap();
45    c.bench_function("mul_scalar", |b| b.iter(|| p.mul_scalar(&r)));
46
47    // c.bench_function("compress", |b| b.iter(|| p.compress()));
48    // let p_comp = p.compress();
49    // c.bench_function("decompress", |b| {
50    //     b.iter(|| babyjubjub_rs::decompress_point(p_comp))
51    // });
52
53    // let sk = babyjubjub_rs::new_key();
54    // let pk = sk.public().unwrap();
55    // let msg = 5.to_bigint().unwrap();
56    // c.bench_function("sign_poseidon", |b| {
57    //     b.iter(|| sk.sign_poseidon(msg.clone()))
58    // });
59    // let sig = sk.sign_poseidon(msg.clone()).unwrap();
60    // c.bench_function("verify_poseidon", |b| {
61    //     b.iter(|| babyjubjub_rs::verify_poseidon(pk.clone(), sig.clone(), msg.clone()))
62    // });
63}
64
65criterion_group!(benches, criterion_benchmark);
66criterion_main!(benches);