2019-10-08 02:25:41 +00:00
|
|
|
use rand_core::SeedableRng;
|
|
|
|
use rand_xorshift::XorShiftRng;
|
2017-09-26 23:42:15 +00:00
|
|
|
|
2018-07-01 01:56:49 +00:00
|
|
|
use ff::Field;
|
2017-09-26 23:42:15 +00:00
|
|
|
use pairing::bls12_381::*;
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench_fq12_add_assign(b: &mut ::test::Bencher) {
|
|
|
|
const SAMPLES: usize = 1000;
|
|
|
|
|
2019-10-08 02:25:41 +00:00
|
|
|
let mut rng = XorShiftRng::from_seed([
|
|
|
|
0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc,
|
|
|
|
0xe5,
|
|
|
|
]);
|
2017-09-26 23:42:15 +00:00
|
|
|
|
2018-05-17 16:50:56 +00:00
|
|
|
let v: Vec<(Fq12, Fq12)> = (0..SAMPLES)
|
2019-10-08 02:25:41 +00:00
|
|
|
.map(|_| (Fq12::random(&mut rng), Fq12::random(&mut rng)))
|
2018-05-17 16:50:56 +00:00
|
|
|
.collect();
|
2017-09-26 23:42:15 +00:00
|
|
|
|
|
|
|
let mut count = 0;
|
|
|
|
b.iter(|| {
|
|
|
|
let mut tmp = v[count].0;
|
|
|
|
tmp.add_assign(&v[count].1);
|
|
|
|
count = (count + 1) % SAMPLES;
|
|
|
|
tmp
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench_fq12_sub_assign(b: &mut ::test::Bencher) {
|
|
|
|
const SAMPLES: usize = 1000;
|
|
|
|
|
2019-10-08 02:25:41 +00:00
|
|
|
let mut rng = XorShiftRng::from_seed([
|
|
|
|
0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc,
|
|
|
|
0xe5,
|
|
|
|
]);
|
2017-09-26 23:42:15 +00:00
|
|
|
|
2018-05-17 16:50:56 +00:00
|
|
|
let v: Vec<(Fq12, Fq12)> = (0..SAMPLES)
|
2019-10-08 02:25:41 +00:00
|
|
|
.map(|_| (Fq12::random(&mut rng), Fq12::random(&mut rng)))
|
2018-05-17 16:50:56 +00:00
|
|
|
.collect();
|
2017-09-26 23:42:15 +00:00
|
|
|
|
|
|
|
let mut count = 0;
|
|
|
|
b.iter(|| {
|
|
|
|
let mut tmp = v[count].0;
|
|
|
|
tmp.sub_assign(&v[count].1);
|
|
|
|
count = (count + 1) % SAMPLES;
|
|
|
|
tmp
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench_fq12_mul_assign(b: &mut ::test::Bencher) {
|
|
|
|
const SAMPLES: usize = 1000;
|
|
|
|
|
2019-10-08 02:25:41 +00:00
|
|
|
let mut rng = XorShiftRng::from_seed([
|
|
|
|
0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc,
|
|
|
|
0xe5,
|
|
|
|
]);
|
2017-09-26 23:42:15 +00:00
|
|
|
|
2018-05-17 16:50:56 +00:00
|
|
|
let v: Vec<(Fq12, Fq12)> = (0..SAMPLES)
|
2019-10-08 02:25:41 +00:00
|
|
|
.map(|_| (Fq12::random(&mut rng), Fq12::random(&mut rng)))
|
2018-05-17 16:50:56 +00:00
|
|
|
.collect();
|
2017-09-26 23:42:15 +00:00
|
|
|
|
|
|
|
let mut count = 0;
|
|
|
|
b.iter(|| {
|
|
|
|
let mut tmp = v[count].0;
|
|
|
|
tmp.mul_assign(&v[count].1);
|
|
|
|
count = (count + 1) % SAMPLES;
|
|
|
|
tmp
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench_fq12_squaring(b: &mut ::test::Bencher) {
|
|
|
|
const SAMPLES: usize = 1000;
|
|
|
|
|
2019-10-08 02:25:41 +00:00
|
|
|
let mut rng = XorShiftRng::from_seed([
|
|
|
|
0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc,
|
|
|
|
0xe5,
|
|
|
|
]);
|
2017-09-26 23:42:15 +00:00
|
|
|
|
2019-10-08 02:25:41 +00:00
|
|
|
let v: Vec<Fq12> = (0..SAMPLES).map(|_| Fq12::random(&mut rng)).collect();
|
2017-09-26 23:42:15 +00:00
|
|
|
|
|
|
|
let mut count = 0;
|
|
|
|
b.iter(|| {
|
|
|
|
let mut tmp = v[count];
|
|
|
|
tmp.square();
|
|
|
|
count = (count + 1) % SAMPLES;
|
|
|
|
tmp
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
|
|
|
fn bench_fq12_inverse(b: &mut ::test::Bencher) {
|
|
|
|
const SAMPLES: usize = 1000;
|
|
|
|
|
2019-10-08 02:25:41 +00:00
|
|
|
let mut rng = XorShiftRng::from_seed([
|
|
|
|
0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc,
|
|
|
|
0xe5,
|
|
|
|
]);
|
2017-09-26 23:42:15 +00:00
|
|
|
|
2019-10-08 02:25:41 +00:00
|
|
|
let v: Vec<Fq12> = (0..SAMPLES).map(|_| Fq12::random(&mut rng)).collect();
|
2017-09-26 23:42:15 +00:00
|
|
|
|
|
|
|
let mut count = 0;
|
|
|
|
b.iter(|| {
|
|
|
|
let tmp = v[count].inverse();
|
|
|
|
count = (count + 1) % SAMPLES;
|
|
|
|
tmp
|
|
|
|
});
|
|
|
|
}
|