Skip to content

Commit

Permalink
test: added benchmarks for G_T (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
alinush authored Sep 30, 2024
1 parent ffbb41d commit c18583e
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions benches/bls12_381/ec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
}
}

0 comments on commit c18583e

Please sign in to comment.