Skip to content

Commit c18583e

Browse files
authored
test: added benchmarks for G_T (#59)
1 parent ffbb41d commit c18583e

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

benches/bls12_381/ec.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,56 @@ mod g2 {
167167
});
168168
}
169169
}
170+
171+
mod gt {
172+
use rand_core::SeedableRng;
173+
use rand_xorshift::XorShiftRng;
174+
175+
use blstrs::*;
176+
use ff::Field;
177+
use group::Group;
178+
179+
#[bench]
180+
fn bench_gt_add_assign(b: &mut ::test::Bencher) {
181+
const SAMPLES: usize = 1000;
182+
183+
let mut rng = XorShiftRng::from_seed([
184+
0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06,
185+
0xbc, 0xe5,
186+
]);
187+
188+
let v: Vec<(Gt, Gt)> = (0..SAMPLES)
189+
.map(|_| (Gt::random(&mut rng), Gt::random(&mut rng)))
190+
.collect();
191+
192+
let mut count = 0;
193+
b.iter(|| {
194+
let mut tmp = v[count].0;
195+
tmp += v[count].1;
196+
count = (count + 1) % SAMPLES;
197+
tmp
198+
});
199+
}
200+
201+
#[bench]
202+
fn bench_gt_mul_assign(b: &mut ::test::Bencher) {
203+
const SAMPLES: usize = 1000;
204+
205+
let mut rng = XorShiftRng::from_seed([
206+
0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06,
207+
0xbc, 0xe5,
208+
]);
209+
210+
let v: Vec<(Gt, Scalar)> = (0..SAMPLES)
211+
.map(|_| (Gt::random(&mut rng), Scalar::random(&mut rng)))
212+
.collect();
213+
214+
let mut count = 0;
215+
b.iter(|| {
216+
let mut tmp = v[count].0;
217+
tmp *= v[count].1;
218+
count = (count + 1) % SAMPLES;
219+
tmp
220+
});
221+
}
222+
}

0 commit comments

Comments
 (0)