From c18583e59e8b2e6d958f3588b6f941c1b5a80ab2 Mon Sep 17 00:00:00 2001 From: Alin Tomescu Date: Mon, 30 Sep 2024 20:16:09 +0200 Subject: [PATCH] test: added benchmarks for G_T (#59) --- benches/bls12_381/ec.rs | 53 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/benches/bls12_381/ec.rs b/benches/bls12_381/ec.rs index 639bcad..4275215 100644 --- a/benches/bls12_381/ec.rs +++ b/benches/bls12_381/ec.rs @@ -167,3 +167,56 @@ mod g2 { }); } } + +mod gt { + use rand_core::SeedableRng; + use rand_xorshift::XorShiftRng; + + use blstrs::*; + use ff::Field; + use group::Group; + + #[bench] + fn bench_gt_add_assign(b: &mut ::test::Bencher) { + const SAMPLES: usize = 1000; + + let mut rng = XorShiftRng::from_seed([ + 0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, + 0xbc, 0xe5, + ]); + + let v: Vec<(Gt, Gt)> = (0..SAMPLES) + .map(|_| (Gt::random(&mut rng), Gt::random(&mut rng))) + .collect(); + + let mut count = 0; + b.iter(|| { + let mut tmp = v[count].0; + tmp += v[count].1; + count = (count + 1) % SAMPLES; + tmp + }); + } + + #[bench] + fn bench_gt_mul_assign(b: &mut ::test::Bencher) { + const SAMPLES: usize = 1000; + + let mut rng = XorShiftRng::from_seed([ + 0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, + 0xbc, 0xe5, + ]); + + let v: Vec<(Gt, Scalar)> = (0..SAMPLES) + .map(|_| (Gt::random(&mut rng), Scalar::random(&mut rng))) + .collect(); + + let mut count = 0; + b.iter(|| { + let mut tmp = v[count].0; + tmp *= v[count].1; + count = (count + 1) % SAMPLES; + tmp + }); + } +}