Apply rustfmt to benchmarks

This commit is contained in:
Sean Bowe 2018-05-17 10:50:56 -06:00
parent 97bdd1655f
commit e4143a4bbc
No known key found for this signature in database
GPG Key ID: 95684257D8F8B031
7 changed files with 152 additions and 128 deletions

@ -10,7 +10,9 @@ mod g1 {
let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);
let v: Vec<(G1, Fr)> = (0..SAMPLES).map(|_| (G1::rand(&mut rng), Fr::rand(&mut rng))).collect(); let v: Vec<(G1, Fr)> = (0..SAMPLES)
.map(|_| (G1::rand(&mut rng), Fr::rand(&mut rng)))
.collect();
let mut count = 0; let mut count = 0;
b.iter(|| { b.iter(|| {
@ -27,7 +29,9 @@ mod g1 {
let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);
let v: Vec<(G1, G1)> = (0..SAMPLES).map(|_| (G1::rand(&mut rng), G1::rand(&mut rng))).collect(); let v: Vec<(G1, G1)> = (0..SAMPLES)
.map(|_| (G1::rand(&mut rng), G1::rand(&mut rng)))
.collect();
let mut count = 0; let mut count = 0;
b.iter(|| { b.iter(|| {
@ -44,7 +48,9 @@ mod g1 {
let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);
let v: Vec<(G1, G1Affine)> = (0..SAMPLES).map(|_| (G1::rand(&mut rng), G1::rand(&mut rng).into())).collect(); let v: Vec<(G1, G1Affine)> = (0..SAMPLES)
.map(|_| (G1::rand(&mut rng), G1::rand(&mut rng).into()))
.collect();
let mut count = 0; let mut count = 0;
b.iter(|| { b.iter(|| {
@ -68,7 +74,9 @@ mod g2 {
let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);
let v: Vec<(G2, Fr)> = (0..SAMPLES).map(|_| (G2::rand(&mut rng), Fr::rand(&mut rng))).collect(); let v: Vec<(G2, Fr)> = (0..SAMPLES)
.map(|_| (G2::rand(&mut rng), Fr::rand(&mut rng)))
.collect();
let mut count = 0; let mut count = 0;
b.iter(|| { b.iter(|| {
@ -85,7 +93,9 @@ mod g2 {
let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);
let v: Vec<(G2, G2)> = (0..SAMPLES).map(|_| (G2::rand(&mut rng), G2::rand(&mut rng))).collect(); let v: Vec<(G2, G2)> = (0..SAMPLES)
.map(|_| (G2::rand(&mut rng), G2::rand(&mut rng)))
.collect();
let mut count = 0; let mut count = 0;
b.iter(|| { b.iter(|| {
@ -102,7 +112,9 @@ mod g2 {
let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);
let v: Vec<(G2, G2Affine)> = (0..SAMPLES).map(|_| (G2::rand(&mut rng), G2::rand(&mut rng).into())).collect(); let v: Vec<(G2, G2Affine)> = (0..SAMPLES)
.map(|_| (G2::rand(&mut rng), G2::rand(&mut rng).into()))
.collect();
let mut count = 0; let mut count = 0;
b.iter(|| { b.iter(|| {

@ -9,16 +9,18 @@ fn bench_fq_repr_add_nocarry(b: &mut ::test::Bencher) {
let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);
let v: Vec<(FqRepr, FqRepr)> = (0..SAMPLES).map(|_| { let v: Vec<(FqRepr, FqRepr)> = (0..SAMPLES)
let mut tmp1 = FqRepr::rand(&mut rng); .map(|_| {
let mut tmp2 = FqRepr::rand(&mut rng); let mut tmp1 = FqRepr::rand(&mut rng);
// Shave a few bits off to avoid overflow. let mut tmp2 = FqRepr::rand(&mut rng);
for _ in 0..3 { // Shave a few bits off to avoid overflow.
tmp1.div2(); for _ in 0..3 {
tmp2.div2(); tmp1.div2();
} tmp2.div2();
(tmp1, tmp2) }
}).collect(); (tmp1, tmp2)
})
.collect();
let mut count = 0; let mut count = 0;
b.iter(|| { b.iter(|| {
@ -35,15 +37,17 @@ fn bench_fq_repr_sub_noborrow(b: &mut ::test::Bencher) {
let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);
let v: Vec<(FqRepr, FqRepr)> = (0..SAMPLES).map(|_| { let v: Vec<(FqRepr, FqRepr)> = (0..SAMPLES)
let tmp1 = FqRepr::rand(&mut rng); .map(|_| {
let mut tmp2 = tmp1; let tmp1 = FqRepr::rand(&mut rng);
// Ensure tmp2 is smaller than tmp1. let mut tmp2 = tmp1;
for _ in 0..10 { // Ensure tmp2 is smaller than tmp1.
tmp2.div2(); for _ in 0..10 {
} tmp2.div2();
(tmp1, tmp2) }
}).collect(); (tmp1, tmp2)
})
.collect();
let mut count = 0; let mut count = 0;
b.iter(|| { b.iter(|| {
@ -110,7 +114,9 @@ fn bench_fq_add_assign(b: &mut ::test::Bencher) {
let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);
let v: Vec<(Fq, Fq)> = (0..SAMPLES).map(|_| (Fq::rand(&mut rng), Fq::rand(&mut rng))).collect(); let v: Vec<(Fq, Fq)> = (0..SAMPLES)
.map(|_| (Fq::rand(&mut rng), Fq::rand(&mut rng)))
.collect();
let mut count = 0; let mut count = 0;
b.iter(|| { b.iter(|| {
@ -127,7 +133,9 @@ fn bench_fq_sub_assign(b: &mut ::test::Bencher) {
let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);
let v: Vec<(Fq, Fq)> = (0..SAMPLES).map(|_| (Fq::rand(&mut rng), Fq::rand(&mut rng))).collect(); let v: Vec<(Fq, Fq)> = (0..SAMPLES)
.map(|_| (Fq::rand(&mut rng), Fq::rand(&mut rng)))
.collect();
let mut count = 0; let mut count = 0;
b.iter(|| { b.iter(|| {
@ -144,7 +152,9 @@ fn bench_fq_mul_assign(b: &mut ::test::Bencher) {
let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);
let v: Vec<(Fq, Fq)> = (0..SAMPLES).map(|_| (Fq::rand(&mut rng), Fq::rand(&mut rng))).collect(); let v: Vec<(Fq, Fq)> = (0..SAMPLES)
.map(|_| (Fq::rand(&mut rng), Fq::rand(&mut rng)))
.collect();
let mut count = 0; let mut count = 0;
b.iter(|| { b.iter(|| {
@ -206,15 +216,17 @@ fn bench_fq_negate(b: &mut ::test::Bencher) {
#[bench] #[bench]
fn bench_fq_sqrt(b: &mut ::test::Bencher) { fn bench_fq_sqrt(b: &mut ::test::Bencher) {
const SAMPLES: usize = 1000; const SAMPLES: usize = 1000;
let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);
let v: Vec<Fq> = (0..SAMPLES).map(|_| { let v: Vec<Fq> = (0..SAMPLES)
let mut tmp = Fq::rand(&mut rng); .map(|_| {
tmp.square(); let mut tmp = Fq::rand(&mut rng);
tmp tmp.square();
}).collect(); tmp
})
.collect();
let mut count = 0; let mut count = 0;
b.iter(|| { b.iter(|| {
@ -229,9 +241,7 @@ fn bench_fq_into_repr(b: &mut ::test::Bencher) {
let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);
let v: Vec<Fq> = (0..SAMPLES).map(|_| { let v: Vec<Fq> = (0..SAMPLES).map(|_| Fq::rand(&mut rng)).collect();
Fq::rand(&mut rng)
}).collect();
let mut count = 0; let mut count = 0;
b.iter(|| { b.iter(|| {
@ -246,9 +256,9 @@ fn bench_fq_from_repr(b: &mut ::test::Bencher) {
let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);
let v: Vec<FqRepr> = (0..SAMPLES).map(|_| { let v: Vec<FqRepr> = (0..SAMPLES)
Fq::rand(&mut rng).into_repr() .map(|_| Fq::rand(&mut rng).into_repr())
}).collect(); .collect();
let mut count = 0; let mut count = 0;
b.iter(|| { b.iter(|| {

@ -9,9 +9,9 @@ fn bench_fq12_add_assign(b: &mut ::test::Bencher) {
let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);
let v: Vec<(Fq12, Fq12)> = (0..SAMPLES).map(|_| { let v: Vec<(Fq12, Fq12)> = (0..SAMPLES)
(Fq12::rand(&mut rng), Fq12::rand(&mut rng)) .map(|_| (Fq12::rand(&mut rng), Fq12::rand(&mut rng)))
}).collect(); .collect();
let mut count = 0; let mut count = 0;
b.iter(|| { b.iter(|| {
@ -28,9 +28,9 @@ fn bench_fq12_sub_assign(b: &mut ::test::Bencher) {
let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);
let v: Vec<(Fq12, Fq12)> = (0..SAMPLES).map(|_| { let v: Vec<(Fq12, Fq12)> = (0..SAMPLES)
(Fq12::rand(&mut rng), Fq12::rand(&mut rng)) .map(|_| (Fq12::rand(&mut rng), Fq12::rand(&mut rng)))
}).collect(); .collect();
let mut count = 0; let mut count = 0;
b.iter(|| { b.iter(|| {
@ -47,9 +47,9 @@ fn bench_fq12_mul_assign(b: &mut ::test::Bencher) {
let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);
let v: Vec<(Fq12, Fq12)> = (0..SAMPLES).map(|_| { let v: Vec<(Fq12, Fq12)> = (0..SAMPLES)
(Fq12::rand(&mut rng), Fq12::rand(&mut rng)) .map(|_| (Fq12::rand(&mut rng), Fq12::rand(&mut rng)))
}).collect(); .collect();
let mut count = 0; let mut count = 0;
b.iter(|| { b.iter(|| {
@ -66,9 +66,7 @@ fn bench_fq12_squaring(b: &mut ::test::Bencher) {
let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);
let v: Vec<Fq12> = (0..SAMPLES).map(|_| { let v: Vec<Fq12> = (0..SAMPLES).map(|_| Fq12::rand(&mut rng)).collect();
Fq12::rand(&mut rng)
}).collect();
let mut count = 0; let mut count = 0;
b.iter(|| { b.iter(|| {
@ -85,9 +83,7 @@ fn bench_fq12_inverse(b: &mut ::test::Bencher) {
let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);
let v: Vec<Fq12> = (0..SAMPLES).map(|_| { let v: Vec<Fq12> = (0..SAMPLES).map(|_| Fq12::rand(&mut rng)).collect();
Fq12::rand(&mut rng)
}).collect();
let mut count = 0; let mut count = 0;
b.iter(|| { b.iter(|| {

@ -9,9 +9,9 @@ fn bench_fq2_add_assign(b: &mut ::test::Bencher) {
let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);
let v: Vec<(Fq2, Fq2)> = (0..SAMPLES).map(|_| { let v: Vec<(Fq2, Fq2)> = (0..SAMPLES)
(Fq2::rand(&mut rng), Fq2::rand(&mut rng)) .map(|_| (Fq2::rand(&mut rng), Fq2::rand(&mut rng)))
}).collect(); .collect();
let mut count = 0; let mut count = 0;
b.iter(|| { b.iter(|| {
@ -28,9 +28,9 @@ fn bench_fq2_sub_assign(b: &mut ::test::Bencher) {
let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);
let v: Vec<(Fq2, Fq2)> = (0..SAMPLES).map(|_| { let v: Vec<(Fq2, Fq2)> = (0..SAMPLES)
(Fq2::rand(&mut rng), Fq2::rand(&mut rng)) .map(|_| (Fq2::rand(&mut rng), Fq2::rand(&mut rng)))
}).collect(); .collect();
let mut count = 0; let mut count = 0;
b.iter(|| { b.iter(|| {
@ -47,9 +47,9 @@ fn bench_fq2_mul_assign(b: &mut ::test::Bencher) {
let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);
let v: Vec<(Fq2, Fq2)> = (0..SAMPLES).map(|_| { let v: Vec<(Fq2, Fq2)> = (0..SAMPLES)
(Fq2::rand(&mut rng), Fq2::rand(&mut rng)) .map(|_| (Fq2::rand(&mut rng), Fq2::rand(&mut rng)))
}).collect(); .collect();
let mut count = 0; let mut count = 0;
b.iter(|| { b.iter(|| {
@ -66,9 +66,7 @@ fn bench_fq2_squaring(b: &mut ::test::Bencher) {
let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);
let v: Vec<Fq2> = (0..SAMPLES).map(|_| { let v: Vec<Fq2> = (0..SAMPLES).map(|_| Fq2::rand(&mut rng)).collect();
Fq2::rand(&mut rng)
}).collect();
let mut count = 0; let mut count = 0;
b.iter(|| { b.iter(|| {
@ -85,9 +83,7 @@ fn bench_fq2_inverse(b: &mut ::test::Bencher) {
let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);
let v: Vec<Fq2> = (0..SAMPLES).map(|_| { let v: Vec<Fq2> = (0..SAMPLES).map(|_| Fq2::rand(&mut rng)).collect();
Fq2::rand(&mut rng)
}).collect();
let mut count = 0; let mut count = 0;
b.iter(|| { b.iter(|| {
@ -103,9 +99,7 @@ fn bench_fq2_sqrt(b: &mut ::test::Bencher) {
let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);
let v: Vec<Fq2> = (0..SAMPLES).map(|_| { let v: Vec<Fq2> = (0..SAMPLES).map(|_| Fq2::rand(&mut rng)).collect();
Fq2::rand(&mut rng)
}).collect();
let mut count = 0; let mut count = 0;
b.iter(|| { b.iter(|| {

@ -9,16 +9,18 @@ fn bench_fr_repr_add_nocarry(b: &mut ::test::Bencher) {
let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);
let v: Vec<(FrRepr, FrRepr)> = (0..SAMPLES).map(|_| { let v: Vec<(FrRepr, FrRepr)> = (0..SAMPLES)
let mut tmp1 = FrRepr::rand(&mut rng); .map(|_| {
let mut tmp2 = FrRepr::rand(&mut rng); let mut tmp1 = FrRepr::rand(&mut rng);
// Shave a few bits off to avoid overflow. let mut tmp2 = FrRepr::rand(&mut rng);
for _ in 0..3 { // Shave a few bits off to avoid overflow.
tmp1.div2(); for _ in 0..3 {
tmp2.div2(); tmp1.div2();
} tmp2.div2();
(tmp1, tmp2) }
}).collect(); (tmp1, tmp2)
})
.collect();
let mut count = 0; let mut count = 0;
b.iter(|| { b.iter(|| {
@ -35,15 +37,17 @@ fn bench_fr_repr_sub_noborrow(b: &mut ::test::Bencher) {
let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);
let v: Vec<(FrRepr, FrRepr)> = (0..SAMPLES).map(|_| { let v: Vec<(FrRepr, FrRepr)> = (0..SAMPLES)
let tmp1 = FrRepr::rand(&mut rng); .map(|_| {
let mut tmp2 = tmp1; let tmp1 = FrRepr::rand(&mut rng);
// Ensure tmp2 is smaller than tmp1. let mut tmp2 = tmp1;
for _ in 0..10 { // Ensure tmp2 is smaller than tmp1.
tmp2.div2(); for _ in 0..10 {
} tmp2.div2();
(tmp1, tmp2) }
}).collect(); (tmp1, tmp2)
})
.collect();
let mut count = 0; let mut count = 0;
b.iter(|| { b.iter(|| {
@ -110,7 +114,9 @@ fn bench_fr_add_assign(b: &mut ::test::Bencher) {
let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);
let v: Vec<(Fr, Fr)> = (0..SAMPLES).map(|_| (Fr::rand(&mut rng), Fr::rand(&mut rng))).collect(); let v: Vec<(Fr, Fr)> = (0..SAMPLES)
.map(|_| (Fr::rand(&mut rng), Fr::rand(&mut rng)))
.collect();
let mut count = 0; let mut count = 0;
b.iter(|| { b.iter(|| {
@ -127,7 +133,9 @@ fn bench_fr_sub_assign(b: &mut ::test::Bencher) {
let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);
let v: Vec<(Fr, Fr)> = (0..SAMPLES).map(|_| (Fr::rand(&mut rng), Fr::rand(&mut rng))).collect(); let v: Vec<(Fr, Fr)> = (0..SAMPLES)
.map(|_| (Fr::rand(&mut rng), Fr::rand(&mut rng)))
.collect();
let mut count = 0; let mut count = 0;
b.iter(|| { b.iter(|| {
@ -144,7 +152,9 @@ fn bench_fr_mul_assign(b: &mut ::test::Bencher) {
let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);
let v: Vec<(Fr, Fr)> = (0..SAMPLES).map(|_| (Fr::rand(&mut rng), Fr::rand(&mut rng))).collect(); let v: Vec<(Fr, Fr)> = (0..SAMPLES)
.map(|_| (Fr::rand(&mut rng), Fr::rand(&mut rng)))
.collect();
let mut count = 0; let mut count = 0;
b.iter(|| { b.iter(|| {
@ -210,11 +220,13 @@ fn bench_fr_sqrt(b: &mut ::test::Bencher) {
let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);
let v: Vec<Fr> = (0..SAMPLES).map(|_| { let v: Vec<Fr> = (0..SAMPLES)
let mut tmp = Fr::rand(&mut rng); .map(|_| {
tmp.square(); let mut tmp = Fr::rand(&mut rng);
tmp tmp.square();
}).collect(); tmp
})
.collect();
let mut count = 0; let mut count = 0;
b.iter(|| { b.iter(|| {
@ -229,9 +241,7 @@ fn bench_fr_into_repr(b: &mut ::test::Bencher) {
let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);
let v: Vec<Fr> = (0..SAMPLES).map(|_| { let v: Vec<Fr> = (0..SAMPLES).map(|_| Fr::rand(&mut rng)).collect();
Fr::rand(&mut rng)
}).collect();
let mut count = 0; let mut count = 0;
b.iter(|| { b.iter(|| {
@ -246,9 +256,9 @@ fn bench_fr_from_repr(b: &mut ::test::Bencher) {
let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);
let v: Vec<FrRepr> = (0..SAMPLES).map(|_| { let v: Vec<FrRepr> = (0..SAMPLES)
Fr::rand(&mut rng).into_repr() .map(|_| Fr::rand(&mut rng).into_repr())
}).collect(); .collect();
let mut count = 0; let mut count = 0;
b.iter(|| { b.iter(|| {

@ -6,7 +6,7 @@ mod ec;
use rand::{Rand, SeedableRng, XorShiftRng}; use rand::{Rand, SeedableRng, XorShiftRng};
use pairing::{Engine, CurveAffine}; use pairing::{CurveAffine, Engine};
use pairing::bls12_381::*; use pairing::bls12_381::*;
#[bench] #[bench]
@ -47,12 +47,14 @@ fn bench_pairing_miller_loop(b: &mut ::test::Bencher) {
let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);
let v: Vec<(G1Prepared, G2Prepared)> = (0..SAMPLES).map(|_| let v: Vec<(G1Prepared, G2Prepared)> = (0..SAMPLES)
( .map(|_| {
G1Affine::from(G1::rand(&mut rng)).prepare(), (
G2Affine::from(G2::rand(&mut rng)).prepare() G1Affine::from(G1::rand(&mut rng)).prepare(),
) G2Affine::from(G2::rand(&mut rng)).prepare(),
).collect(); )
})
.collect();
let mut count = 0; let mut count = 0;
b.iter(|| { b.iter(|| {
@ -68,12 +70,15 @@ fn bench_pairing_final_exponentiation(b: &mut ::test::Bencher) {
let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);
let v: Vec<Fq12> = (0..SAMPLES).map(|_| let v: Vec<Fq12> = (0..SAMPLES)
( .map(|_| {
G1Affine::from(G1::rand(&mut rng)).prepare(), (
G2Affine::from(G2::rand(&mut rng)).prepare() G1Affine::from(G1::rand(&mut rng)).prepare(),
) G2Affine::from(G2::rand(&mut rng)).prepare(),
).map(|(ref p, ref q)| Bls12::miller_loop(&[(p, q)])).collect(); )
})
.map(|(ref p, ref q)| Bls12::miller_loop(&[(p, q)]))
.collect();
let mut count = 0; let mut count = 0;
b.iter(|| { b.iter(|| {
@ -89,12 +94,9 @@ fn bench_pairing_full(b: &mut ::test::Bencher) {
let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]); let mut rng = XorShiftRng::from_seed([0x5dbe6259, 0x8d313d76, 0x3237db17, 0xe5bc0654]);
let v: Vec<(G1, G2)> = (0..SAMPLES).map(|_| let v: Vec<(G1, G2)> = (0..SAMPLES)
( .map(|_| (G1::rand(&mut rng), G2::rand(&mut rng)))
G1::rand(&mut rng), .collect();
G2::rand(&mut rng)
)
).collect();
let mut count = 0; let mut count = 0;
b.iter(|| { b.iter(|| {
@ -102,4 +104,4 @@ fn bench_pairing_full(b: &mut ::test::Bencher) {
count = (count + 1) % SAMPLES; count = (count + 1) % SAMPLES;
tmp tmp
}); });
} }

@ -1,7 +1,7 @@
#![feature(test)] #![feature(test)]
extern crate test;
extern crate rand;
extern crate pairing; extern crate pairing;
extern crate rand;
extern crate test;
mod bls12_381; mod bls12_381;