2019-12-19 16:46:16 -06:00
|
|
|
pub(crate) mod g1 {
|
|
|
|
use criterion::{criterion_group, Criterion};
|
2019-10-08 15:25:41 +13:00
|
|
|
use rand_core::SeedableRng;
|
|
|
|
use rand_xorshift::XorShiftRng;
|
2019-05-27 17:15:16 +01:00
|
|
|
use std::ops::AddAssign;
|
2017-09-27 00:42:15 +01:00
|
|
|
|
2019-10-08 15:25:41 +13:00
|
|
|
use ff::Field;
|
2018-07-02 12:50:47 +01:00
|
|
|
use group::CurveProjective;
|
2017-09-27 00:42:15 +01:00
|
|
|
use pairing::bls12_381::*;
|
|
|
|
|
2019-12-19 16:46:16 -06:00
|
|
|
fn bench_g1_mul_assign(c: &mut Criterion) {
|
2017-09-27 00:42:15 +01:00
|
|
|
const SAMPLES: usize = 1000;
|
|
|
|
|
2019-10-08 15:25:41 +13: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-27 00:42:15 +01:00
|
|
|
|
2018-05-17 10:50:56 -06:00
|
|
|
let v: Vec<(G1, Fr)> = (0..SAMPLES)
|
2019-10-08 15:25:41 +13:00
|
|
|
.map(|_| (G1::random(&mut rng), Fr::random(&mut rng)))
|
2018-05-17 10:50:56 -06:00
|
|
|
.collect();
|
2017-09-27 00:42:15 +01:00
|
|
|
|
|
|
|
let mut count = 0;
|
2019-12-19 16:46:16 -06:00
|
|
|
c.bench_function("G1::mul_assign", |b| {
|
|
|
|
b.iter(|| {
|
|
|
|
let mut tmp = v[count].0;
|
|
|
|
tmp.mul_assign(v[count].1);
|
|
|
|
count = (count + 1) % SAMPLES;
|
|
|
|
tmp
|
|
|
|
})
|
2017-09-27 00:42:15 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-12-19 16:46:16 -06:00
|
|
|
fn bench_g1_add_assign(c: &mut Criterion) {
|
2017-09-27 00:42:15 +01:00
|
|
|
const SAMPLES: usize = 1000;
|
|
|
|
|
2019-10-08 15:25:41 +13: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-27 00:42:15 +01:00
|
|
|
|
2018-05-17 10:50:56 -06:00
|
|
|
let v: Vec<(G1, G1)> = (0..SAMPLES)
|
2019-10-08 15:25:41 +13:00
|
|
|
.map(|_| (G1::random(&mut rng), G1::random(&mut rng)))
|
2018-05-17 10:50:56 -06:00
|
|
|
.collect();
|
2017-09-27 00:42:15 +01:00
|
|
|
|
|
|
|
let mut count = 0;
|
2019-12-19 16:46:16 -06:00
|
|
|
c.bench_function("G1::add_assign", |b| {
|
|
|
|
b.iter(|| {
|
|
|
|
let mut tmp = v[count].0;
|
|
|
|
tmp.add_assign(&v[count].1);
|
|
|
|
count = (count + 1) % SAMPLES;
|
|
|
|
tmp
|
|
|
|
})
|
2017-09-27 00:42:15 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-12-19 16:46:16 -06:00
|
|
|
fn bench_g1_add_assign_mixed(c: &mut Criterion) {
|
2017-09-27 00:42:15 +01:00
|
|
|
const SAMPLES: usize = 1000;
|
|
|
|
|
2019-10-08 15:25:41 +13: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-27 00:42:15 +01:00
|
|
|
|
2018-05-17 10:50:56 -06:00
|
|
|
let v: Vec<(G1, G1Affine)> = (0..SAMPLES)
|
2019-10-08 15:25:41 +13:00
|
|
|
.map(|_| (G1::random(&mut rng), G1::random(&mut rng).into()))
|
2018-05-17 10:50:56 -06:00
|
|
|
.collect();
|
2017-09-27 00:42:15 +01:00
|
|
|
|
|
|
|
let mut count = 0;
|
2019-12-19 16:46:16 -06:00
|
|
|
c.bench_function("G1::add_assign_mixed", |b| {
|
|
|
|
b.iter(|| {
|
|
|
|
let mut tmp = v[count].0;
|
2019-12-14 17:20:47 +00:00
|
|
|
tmp.add_assign(&v[count].1);
|
2019-12-19 16:46:16 -06:00
|
|
|
count = (count + 1) % SAMPLES;
|
|
|
|
tmp
|
|
|
|
})
|
2017-09-27 00:42:15 +01:00
|
|
|
});
|
|
|
|
}
|
2019-12-19 16:46:16 -06:00
|
|
|
|
|
|
|
criterion_group!(
|
|
|
|
benches,
|
|
|
|
bench_g1_add_assign,
|
|
|
|
bench_g1_add_assign_mixed,
|
|
|
|
bench_g1_mul_assign,
|
|
|
|
);
|
2017-09-27 00:42:15 +01:00
|
|
|
}
|
|
|
|
|
2019-12-19 16:46:16 -06:00
|
|
|
pub(crate) mod g2 {
|
|
|
|
use criterion::{criterion_group, Criterion};
|
2019-10-08 15:25:41 +13:00
|
|
|
use rand_core::SeedableRng;
|
|
|
|
use rand_xorshift::XorShiftRng;
|
2019-05-27 17:15:16 +01:00
|
|
|
use std::ops::AddAssign;
|
2017-09-27 00:42:15 +01:00
|
|
|
|
2019-10-08 15:25:41 +13:00
|
|
|
use ff::Field;
|
2018-07-02 12:50:47 +01:00
|
|
|
use group::CurveProjective;
|
2017-09-27 00:42:15 +01:00
|
|
|
use pairing::bls12_381::*;
|
|
|
|
|
2019-12-19 16:46:16 -06:00
|
|
|
fn bench_g2_mul_assign(c: &mut Criterion) {
|
2017-09-27 00:42:15 +01:00
|
|
|
const SAMPLES: usize = 1000;
|
|
|
|
|
2019-10-08 15:25:41 +13: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-27 00:42:15 +01:00
|
|
|
|
2018-05-17 10:50:56 -06:00
|
|
|
let v: Vec<(G2, Fr)> = (0..SAMPLES)
|
2019-10-08 15:25:41 +13:00
|
|
|
.map(|_| (G2::random(&mut rng), Fr::random(&mut rng)))
|
2018-05-17 10:50:56 -06:00
|
|
|
.collect();
|
2017-09-27 00:42:15 +01:00
|
|
|
|
|
|
|
let mut count = 0;
|
2019-12-19 16:46:16 -06:00
|
|
|
c.bench_function("G2::mul_assign", |b| {
|
|
|
|
b.iter(|| {
|
|
|
|
let mut tmp = v[count].0;
|
|
|
|
tmp.mul_assign(v[count].1);
|
|
|
|
count = (count + 1) % SAMPLES;
|
|
|
|
tmp
|
|
|
|
})
|
2017-09-27 00:42:15 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-12-19 16:46:16 -06:00
|
|
|
fn bench_g2_add_assign(c: &mut Criterion) {
|
2017-09-27 00:42:15 +01:00
|
|
|
const SAMPLES: usize = 1000;
|
|
|
|
|
2019-10-08 15:25:41 +13: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-27 00:42:15 +01:00
|
|
|
|
2018-05-17 10:50:56 -06:00
|
|
|
let v: Vec<(G2, G2)> = (0..SAMPLES)
|
2019-10-08 15:25:41 +13:00
|
|
|
.map(|_| (G2::random(&mut rng), G2::random(&mut rng)))
|
2018-05-17 10:50:56 -06:00
|
|
|
.collect();
|
2017-09-27 00:42:15 +01:00
|
|
|
|
|
|
|
let mut count = 0;
|
2019-12-19 16:46:16 -06:00
|
|
|
c.bench_function("G2::add_assign", |b| {
|
|
|
|
b.iter(|| {
|
|
|
|
let mut tmp = v[count].0;
|
|
|
|
tmp.add_assign(&v[count].1);
|
|
|
|
count = (count + 1) % SAMPLES;
|
|
|
|
tmp
|
|
|
|
})
|
2017-09-27 00:42:15 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-12-19 16:46:16 -06:00
|
|
|
fn bench_g2_add_assign_mixed(c: &mut Criterion) {
|
2017-09-27 00:42:15 +01:00
|
|
|
const SAMPLES: usize = 1000;
|
|
|
|
|
2019-10-08 15:25:41 +13: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-27 00:42:15 +01:00
|
|
|
|
2018-05-17 10:50:56 -06:00
|
|
|
let v: Vec<(G2, G2Affine)> = (0..SAMPLES)
|
2019-10-08 15:25:41 +13:00
|
|
|
.map(|_| (G2::random(&mut rng), G2::random(&mut rng).into()))
|
2018-05-17 10:50:56 -06:00
|
|
|
.collect();
|
2017-09-27 00:42:15 +01:00
|
|
|
|
|
|
|
let mut count = 0;
|
2019-12-19 16:46:16 -06:00
|
|
|
c.bench_function("G2::add_assign_mixed", |b| {
|
|
|
|
b.iter(|| {
|
|
|
|
let mut tmp = v[count].0;
|
2019-12-14 17:20:47 +00:00
|
|
|
tmp.add_assign(&v[count].1);
|
2019-12-19 16:46:16 -06:00
|
|
|
count = (count + 1) % SAMPLES;
|
|
|
|
tmp
|
|
|
|
})
|
2017-09-27 00:42:15 +01:00
|
|
|
});
|
|
|
|
}
|
2019-12-19 16:46:16 -06:00
|
|
|
|
|
|
|
criterion_group!(
|
|
|
|
benches,
|
|
|
|
bench_g2_add_assign,
|
|
|
|
bench_g2_add_assign_mixed,
|
|
|
|
bench_g2_mul_assign,
|
|
|
|
);
|
2017-09-27 00:42:15 +01:00
|
|
|
}
|