ark-curves-cherry-picked/curve-benches/src/macros/pairing.rs
curve-benches/src/macros/pairing.rsRaw
1macro_rules! pairing_bench {
2 ($curve:ident, $pairing_field:ident, $pairing_type:ident) => {
3 #[bench]
4 fn bench_pairing_miller_loop(b: &mut ::test::Bencher) {
5 const SAMPLES: usize = 1000;
6
7 let mut rng = XorShiftRng::seed_from_u64(1231275789u64);
8
9 $pairing_type!(v, rng);
10
11 let mut count = 0;
12 b.iter(|| {
13 let tmp = $curve::miller_loop(&[(v[count].0.clone(), v[count].1.clone())]);
14 count = (count + 1) % SAMPLES;
15 tmp
16 });
17 }
18
19 #[bench]
20 fn bench_pairing_final_exponentiation(b: &mut ::test::Bencher) {
21 const SAMPLES: usize = 1000;
22
23 let mut rng = XorShiftRng::seed_from_u64(1231275789u64);
24
25 let v: Vec<$pairing_field> = (0..SAMPLES)
26 .map(|_| {
27 (
28 G1Affine::from(G1::rand(&mut rng)).into(),
29 G2Affine::from(G2::rand(&mut rng)).into(),
30 )
31 })
32 .map(|(p, q)| $curve::miller_loop(&[(p, q)]))
33 .collect();
34
35 let mut count = 0;
36 b.iter(|| {
37 let tmp = $curve::final_exponentiation(&v[count]);
38 count = (count + 1) % SAMPLES;
39 tmp
40 });
41 }
42
43 #[bench]
44 fn bench_pairing_full(b: &mut ::test::Bencher) {
45 const SAMPLES: usize = 1000;
46
47 let mut rng = XorShiftRng::seed_from_u64(1231275789u64);
48
49 let v: Vec<(G1, G2)> = (0..SAMPLES)
50 .map(|_| (G1::rand(&mut rng), G2::rand(&mut rng)))
51 .collect();
52
53 let mut count = 0;
54 b.iter(|| {
55 let tmp = $curve::pairing(v[count].0, v[count].1);
56 count = (count + 1) % SAMPLES;
57 tmp
58 });
59 }
60 };
61}