Browse Source

Fix benchmark compilation and add benchmarks for Edwards curves

fq2_neg_nonresidue
Pratyush Mishra 4 years ago
parent
commit
c4e4e18dee
13 changed files with 160 additions and 235 deletions
  1. +2
    -1
      curve-benches/Cargo.toml
  2. +10
    -2
      curve-benches/src/curves/bls12_377.rs
  3. +10
    -2
      curve-benches/src/curves/bls12_381.rs
  4. +14
    -6
      curve-benches/src/curves/bn254.rs
  5. +10
    -2
      curve-benches/src/curves/bw6_761.rs
  6. +10
    -2
      curve-benches/src/curves/cp6_782.rs
  7. +18
    -0
      curve-benches/src/curves/ed_on_bls12_381.rs
  8. +10
    -2
      curve-benches/src/curves/mnt4_298.rs
  9. +10
    -2
      curve-benches/src/curves/mnt4_753.rs
  10. +10
    -2
      curve-benches/src/curves/mnt6_298.rs
  11. +10
    -2
      curve-benches/src/curves/mnt6_753.rs
  12. +11
    -9
      curve-benches/src/curves/mod.rs
  13. +35
    -203
      curve-benches/src/macros/ec.rs

+ 2
- 1
curve-benches/Cargo.toml

@ -32,9 +32,10 @@ ark-mnt4-298 = { path = "../mnt4_298", optional = true }
ark-mnt6-298 = { path = "../mnt6_298", optional = true } ark-mnt6-298 = { path = "../mnt6_298", optional = true }
ark-mnt4-753 = { path = "../mnt4_753", optional = true } ark-mnt4-753 = { path = "../mnt4_753", optional = true }
ark-mnt6-753 = { path = "../mnt6_753", optional = true } ark-mnt6-753 = { path = "../mnt6_753", optional = true }
ark-bn254 = { path = "../bn254", default-features = false, optional = true }
ark-bn254 = { path = "../bn254", optional = true }
ark-bls12-377 = { path = "../bls12_377", optional = true } ark-bls12-377 = { path = "../bls12_377", optional = true }
ark-bls12-381 = { path = "../bls12_381", optional = true } ark-bls12-381 = { path = "../bls12_381", optional = true }
ark-ed-on-bls12-381 = { path = "../ed_on_bls12_381", optional = true }
ark-bw6-761 = { path = "../bw6_761", optional = true } ark-bw6-761 = { path = "../bw6_761", optional = true }
ark-cp6-782 = { path = "../cp6_782", optional = true } ark-cp6-782 = { path = "../cp6_782", optional = true }

+ 10
- 2
curve-benches/src/curves/bls12_377.rs

@ -2,7 +2,7 @@ use rand::SeedableRng;
use rand_xorshift::XorShiftRng; use rand_xorshift::XorShiftRng;
use std::ops::{AddAssign, MulAssign, SubAssign}; use std::ops::{AddAssign, MulAssign, SubAssign};
use ark_bls12_377::bls12_377::{
use ark_bls12_377::{
fq::Fq, fq2::Fq2, fr::Fr, Bls12_377, Fq12, G1Affine, G1Projective as G1, G2Affine, fq::Fq, fq2::Fq2, fr::Fr, Bls12_377, Fq12, G1Affine, G1Projective as G1, G2Affine,
G2Projective as G2, Parameters, G2Projective as G2, Parameters,
}; };
@ -15,7 +15,15 @@ use ark_ff::{
BigInteger, Field, PrimeField, SquareRootField, UniformRand, BigInteger, Field, PrimeField, SquareRootField, UniformRand,
}; };
ec_bench!();
mod g1 {
use super::*;
ec_bench!(G1, G1Affine);
}
mod g2 {
use super::*;
ec_bench!(G2, G2Affine);
}
f_bench!(1, Fq2, Fq2, fq2); f_bench!(1, Fq2, Fq2, fq2);
f_bench!(2, Fq12, Fq12, fq12); f_bench!(2, Fq12, Fq12, fq12);
f_bench!(Fq, Fq, FqRepr, FqRepr, fq); f_bench!(Fq, Fq, FqRepr, FqRepr, fq);

+ 10
- 2
curve-benches/src/curves/bls12_381.rs

@ -2,7 +2,7 @@ use rand::SeedableRng;
use rand_xorshift::XorShiftRng; use rand_xorshift::XorShiftRng;
use std::ops::{AddAssign, MulAssign, SubAssign}; use std::ops::{AddAssign, MulAssign, SubAssign};
use ark_bls12_381::bls12_381::{
use ark_bls12_381::{
fq::Fq, fq2::Fq2, fr::Fr, Bls12_381, Fq12, G1Affine, G1Projective as G1, G2Affine, fq::Fq, fq2::Fq2, fr::Fr, Bls12_381, Fq12, G1Affine, G1Projective as G1, G2Affine,
G2Projective as G2, Parameters, G2Projective as G2, Parameters,
}; };
@ -15,7 +15,15 @@ use ark_ff::{
BigInteger, Field, PrimeField, SquareRootField, UniformRand, BigInteger, Field, PrimeField, SquareRootField, UniformRand,
}; };
ec_bench!();
mod g1 {
use super::*;
ec_bench!(G1, G1Affine);
}
mod g2 {
use super::*;
ec_bench!(G2, G2Affine);
}
f_bench!(1, Fq2, Fq2, fq2); f_bench!(1, Fq2, Fq2, fq2);
f_bench!(2, Fq12, Fq12, fq12); f_bench!(2, Fq12, Fq12, fq12);
f_bench!(Fq, Fq, FqRepr, FqRepr, fq); f_bench!(Fq, Fq, FqRepr, FqRepr, fq);

+ 14
- 6
curve-benches/src/curves/bn254.rs

@ -2,20 +2,28 @@ use rand::SeedableRng;
use rand_xorshift::XorShiftRng; use rand_xorshift::XorShiftRng;
use std::ops::{AddAssign, MulAssign, SubAssign}; use std::ops::{AddAssign, MulAssign, SubAssign};
use ark_bn254::{
fq::Fq, fq2::Fq2, fr::Fr, Bn254, Fq12, G1Affine, G1Projective as G1, G2Affine,
G2Projective as G2, Parameters,
};
use ark_ec::{ use ark_ec::{
bn::{G1Prepared, G2Prepared}, bn::{G1Prepared, G2Prepared},
PairingEngine, ProjectiveCurve, PairingEngine, ProjectiveCurve,
}; };
use ark_ef::{
use ark_ff::{
biginteger::{BigInteger256 as FrRepr, BigInteger256 as FqRepr}, biginteger::{BigInteger256 as FrRepr, BigInteger256 as FqRepr},
BigInteger, Field, PrimeField, SquareRootField, UniformRand, BigInteger, Field, PrimeField, SquareRootField, UniformRand,
}; };
use ark_en254::bn254::{
fq::Fq, fq2::Fq2, fr::Fr, Bls12_381, Fq12, G1Affine, G1Projective as G1, G2Affine,
G2Projective as G2, Parameters,
};
ec_bench!();
mod g1 {
use super::*;
ec_bench!(G1, G1Affine);
}
mod g2 {
use super::*;
ec_bench!(G2, G2Affine);
}
f_bench!(1, Fq2, Fq2, fq2); f_bench!(1, Fq2, Fq2, fq2);
f_bench!(2, Fq12, Fq12, fq12); f_bench!(2, Fq12, Fq12, fq12);
f_bench!(Fq, Fq, FqRepr, FqRepr, fq); f_bench!(Fq, Fq, FqRepr, FqRepr, fq);

+ 10
- 2
curve-benches/src/curves/bw6_761.rs

@ -2,7 +2,7 @@ use rand::SeedableRng;
use rand_xorshift::XorShiftRng; use rand_xorshift::XorShiftRng;
use std::ops::{AddAssign, MulAssign, SubAssign}; use std::ops::{AddAssign, MulAssign, SubAssign};
use ark_bls12_377::bw6_761::{
use ark_bw6_761::{
fq::Fq, fq3::Fq3, fr::Fr, Fq6, G1Affine, G1Projective as G1, G2Affine, G2Projective as G2, fq::Fq, fq3::Fq3, fr::Fr, Fq6, G1Affine, G1Projective as G1, G2Affine, G2Projective as G2,
Parameters, BW6_761, Parameters, BW6_761,
}; };
@ -15,7 +15,15 @@ use ark_ff::{
BigInteger, Field, PrimeField, SquareRootField, UniformRand, BigInteger, Field, PrimeField, SquareRootField, UniformRand,
}; };
ec_bench!();
mod g1 {
use super::*;
ec_bench!(G1, G1Affine);
}
mod g2 {
use super::*;
ec_bench!(G2, G2Affine);
}
f_bench!(1, Fq3, Fq3, fq3); f_bench!(1, Fq3, Fq3, fq3);
f_bench!(2, Fq6, Fq6, fq6); f_bench!(2, Fq6, Fq6, fq6);
f_bench!(Fq, Fq, FqRepr, FqRepr, fq); f_bench!(Fq, Fq, FqRepr, FqRepr, fq);

+ 10
- 2
curve-benches/src/curves/cp6_782.rs

@ -2,7 +2,7 @@ use rand::SeedableRng;
use rand_xorshift::XorShiftRng; use rand_xorshift::XorShiftRng;
use std::ops::{AddAssign, MulAssign, SubAssign}; use std::ops::{AddAssign, MulAssign, SubAssign};
use ark_bls12_377::cp6_782::{
use ark_cp6_782::{
fq::Fq, fq3::Fq3, fr::Fr, Fq6, G1Affine, G1Projective as G1, G2Affine, G2Projective as G2, fq::Fq, fq3::Fq3, fr::Fr, Fq6, G1Affine, G1Projective as G1, G2Affine, G2Projective as G2,
CP6_782, CP6_782,
}; };
@ -12,7 +12,15 @@ use ark_ff::{
BigInteger, Field, PrimeField, SquareRootField, UniformRand, BigInteger, Field, PrimeField, SquareRootField, UniformRand,
}; };
ec_bench!();
mod g1 {
use super::*;
ec_bench!(G1, G1Affine);
}
mod g2 {
use super::*;
ec_bench!(G2, G2Affine);
}
f_bench!(1, Fq3, Fq3, fq3); f_bench!(1, Fq3, Fq3, fq3);
f_bench!(2, Fq6, Fq6, fq6); f_bench!(2, Fq6, Fq6, fq6);
f_bench!(Fq, Fq, FqRepr, FqRepr, fq); f_bench!(Fq, Fq, FqRepr, FqRepr, fq);

+ 18
- 0
curve-benches/src/curves/ed_on_bls12_381.rs

@ -0,0 +1,18 @@
use rand::SeedableRng;
use rand_xorshift::XorShiftRng;
use std::ops::{AddAssign, MulAssign, SubAssign};
use ark_ec::ProjectiveCurve;
use ark_ed_on_bls12_381::{fq::Fq, fr::Fr, EdwardsAffine as GAffine, EdwardsProjective as G};
use ark_ff::{
biginteger::{BigInteger256 as FrRepr, BigInteger256 as FqRepr},
BigInteger, Field, PrimeField, SquareRootField, UniformRand,
};
mod g {
use super::*;
ec_bench!(G, GAffine);
}
f_bench!(Fq, Fq, FqRepr, FqRepr, fq);
f_bench!(Fr, Fr, FrRepr, FrRepr, fr);

+ 10
- 2
curve-benches/src/curves/mnt4_298.rs

@ -10,12 +10,20 @@ use ark_ff::{
biginteger::BigInteger320 as FqRepr, BigInteger, Field, PrimeField, SquareRootField, biginteger::BigInteger320 as FqRepr, BigInteger, Field, PrimeField, SquareRootField,
UniformRand, UniformRand,
}; };
use ark_mnt_298::mnt4_298::{
use ark_mnt4_298::{
fq::Fq, fq2::Fq2, fr::Fr, Fq4, G1Affine, G1Projective as G1, G2Affine, G2Projective as G2, fq::Fq, fq2::Fq2, fr::Fr, Fq4, G1Affine, G1Projective as G1, G2Affine, G2Projective as G2,
Parameters, MNT4_298, Parameters, MNT4_298,
}; };
ec_bench!();
mod g1 {
use super::*;
ec_bench!(G1, G1Affine);
}
mod g2 {
use super::*;
ec_bench!(G2, G2Affine);
}
f_bench!(1, Fq2, Fq2, fq2); f_bench!(1, Fq2, Fq2, fq2);
f_bench!(2, Fq4, Fq4, fq4); f_bench!(2, Fq4, Fq4, fq4);
f_bench!(Fq, Fq, FqRepr, FqRepr, fq); f_bench!(Fq, Fq, FqRepr, FqRepr, fq);

+ 10
- 2
curve-benches/src/curves/mnt4_753.rs

@ -10,12 +10,20 @@ use ark_ff::{
biginteger::BigInteger768 as FqRepr, BigInteger, Field, PrimeField, SquareRootField, biginteger::BigInteger768 as FqRepr, BigInteger, Field, PrimeField, SquareRootField,
UniformRand, UniformRand,
}; };
use ark_mnt_753::mnt4_753::{
use ark_mnt4_753::{
fq::Fq, fq2::Fq2, fr::Fr, Fq4, G1Affine, G1Projective as G1, G2Affine, G2Projective as G2, fq::Fq, fq2::Fq2, fr::Fr, Fq4, G1Affine, G1Projective as G1, G2Affine, G2Projective as G2,
Parameters, MNT4_753, Parameters, MNT4_753,
}; };
ec_bench!();
mod g1 {
use super::*;
ec_bench!(G1, G1Affine);
}
mod g2 {
use super::*;
ec_bench!(G2, G2Affine);
}
f_bench!(1, Fq2, Fq2, fq2); f_bench!(1, Fq2, Fq2, fq2);
f_bench!(2, Fq4, Fq4, fq4); f_bench!(2, Fq4, Fq4, fq4);
f_bench!(Fq, Fq, FqRepr, FqRepr, fq); f_bench!(Fq, Fq, FqRepr, FqRepr, fq);

+ 10
- 2
curve-benches/src/curves/mnt6_298.rs

@ -10,12 +10,20 @@ use ark_ff::{
biginteger::BigInteger320 as FqRepr, BigInteger, Field, PrimeField, SquareRootField, biginteger::BigInteger320 as FqRepr, BigInteger, Field, PrimeField, SquareRootField,
UniformRand, UniformRand,
}; };
use ark_mnt_298::mnt6_298::{
use ark_mnt6_298::{
fq::Fq, fq3::Fq3, fr::Fr, Fq6, G1Affine, G1Projective as G1, G2Affine, G2Projective as G2, fq::Fq, fq3::Fq3, fr::Fr, Fq6, G1Affine, G1Projective as G1, G2Affine, G2Projective as G2,
Parameters, MNT6_298, Parameters, MNT6_298,
}; };
ec_bench!();
mod g1 {
use super::*;
ec_bench!(G1, G1Affine);
}
mod g2 {
use super::*;
ec_bench!(G2, G2Affine);
}
f_bench!(1, Fq3, Fq3, fq3); f_bench!(1, Fq3, Fq3, fq3);
f_bench!(2, Fq6, Fq6, fq6); f_bench!(2, Fq6, Fq6, fq6);
f_bench!(Fq, Fq, FqRepr, FqRepr, fq); f_bench!(Fq, Fq, FqRepr, FqRepr, fq);

+ 10
- 2
curve-benches/src/curves/mnt6_753.rs

@ -10,12 +10,20 @@ use ark_ff::{
biginteger::BigInteger768 as FqRepr, BigInteger, Field, PrimeField, SquareRootField, biginteger::BigInteger768 as FqRepr, BigInteger, Field, PrimeField, SquareRootField,
UniformRand, UniformRand,
}; };
use ark_mnt_753::mnt6_753::{
use ark_mnt6_753::{
fq::Fq, fq3::Fq3, fr::Fr, Fq6, G1Affine, G1Projective as G1, G2Affine, G2Projective as G2, fq::Fq, fq3::Fq3, fr::Fr, Fq6, G1Affine, G1Projective as G1, G2Affine, G2Projective as G2,
Parameters, MNT6_753, Parameters, MNT6_753,
}; };
ec_bench!();
mod g1 {
use super::*;
ec_bench!(G1, G1Affine);
}
mod g2 {
use super::*;
ec_bench!(G2, G2Affine);
}
f_bench!(1, Fq3, Fq3, fq3); f_bench!(1, Fq3, Fq3, fq3);
f_bench!(2, Fq6, Fq6, fq6); f_bench!(2, Fq6, Fq6, fq6);
f_bench!(Fq, Fq, FqRepr, FqRepr, fq); f_bench!(Fq, Fq, FqRepr, FqRepr, fq);

+ 11
- 9
curve-benches/src/curves/mod.rs

@ -1,18 +1,20 @@
#[cfg(feature = "bls12_377")]
#[cfg(feature = "ark-bls12-377")]
mod bls12_377; mod bls12_377;
#[cfg(feature = "bls12_381")]
#[cfg(feature = "ark-bls12-381")]
mod bls12_381; mod bls12_381;
#[cfg(feature = "bn254")]
#[cfg(feature = "ark-bn254")]
mod bn254; mod bn254;
#[cfg(feature = "bw6_761")]
#[cfg(feature = "ark-bw6-761")]
mod bw6_761; mod bw6_761;
#[cfg(feature = "cp6_782")]
#[cfg(feature = "ark-cp6-782")]
mod cp6_782; mod cp6_782;
#[cfg(feature = "mnt4_298")]
#[cfg(feature = "ark-ed-on-bls12-381")]
mod ed_on_bls12_381;
#[cfg(feature = "ark-mnt4-298")]
mod mnt4_298; mod mnt4_298;
#[cfg(feature = "mnt4_753")]
#[cfg(feature = "ark-mnt4-753")]
mod mnt4_753; mod mnt4_753;
#[cfg(feature = "mnt6_298")]
#[cfg(feature = "ark-mnt6-298")]
mod mnt6_298; mod mnt6_298;
#[cfg(feature = "mnt6_753")]
#[cfg(feature = "ark-mnt6-753")]
mod mnt6_753; mod mnt6_753;

+ 35
- 203
curve-benches/src/macros/ec.rs

@ -1,19 +1,19 @@
macro_rules! ec_bench { macro_rules! ec_bench {
() => {
($projective:ty, $affine:ty) => {
#[bench] #[bench]
fn bench_g1_rand(b: &mut ::test::Bencher) {
fn bench_rand(b: &mut ::test::Bencher) {
let mut rng = XorShiftRng::seed_from_u64(1231275789u64); let mut rng = XorShiftRng::seed_from_u64(1231275789u64);
b.iter(|| G1::rand(&mut rng));
b.iter(|| <$projective>::rand(&mut rng));
} }
#[bench] #[bench]
fn bench_g1_mul_assign(b: &mut ::test::Bencher) {
fn bench_mul_assign(b: &mut ::test::Bencher) {
const SAMPLES: usize = 1000; const SAMPLES: usize = 1000;
let mut rng = XorShiftRng::seed_from_u64(1231275789u64); let mut rng = XorShiftRng::seed_from_u64(1231275789u64);
let v: Vec<(G1, Fr)> = (0..SAMPLES)
.map(|_| (G1::rand(&mut rng), Fr::rand(&mut rng)))
let v: Vec<($projective, Fr)> = (0..SAMPLES)
.map(|_| (<$projective>::rand(&mut rng), Fr::rand(&mut rng)))
.collect(); .collect();
let mut count = 0; let mut count = 0;
@ -26,13 +26,13 @@ macro_rules! ec_bench {
} }
#[bench] #[bench]
fn bench_g1_add_assign(b: &mut ::test::Bencher) {
fn bench_add_assign(b: &mut ::test::Bencher) {
const SAMPLES: usize = 1000; const SAMPLES: usize = 1000;
let mut rng = XorShiftRng::seed_from_u64(1231275789u64); let mut rng = XorShiftRng::seed_from_u64(1231275789u64);
let v: Vec<(G1, G1)> = (0..SAMPLES)
.map(|_| (G1::rand(&mut rng), G1::rand(&mut rng)))
let v: Vec<($projective, $projective)> = (0..SAMPLES)
.map(|_| (<$projective>::rand(&mut rng), <$projective>::rand(&mut rng)))
.collect(); .collect();
let mut count = 0; let mut count = 0;
@ -45,13 +45,18 @@ macro_rules! ec_bench {
} }
#[bench] #[bench]
fn bench_g1_add_assign_mixed(b: &mut ::test::Bencher) {
fn bench_add_assign_mixed(b: &mut ::test::Bencher) {
const SAMPLES: usize = 1000; const SAMPLES: usize = 1000;
let mut rng = XorShiftRng::seed_from_u64(1231275789u64); let mut rng = XorShiftRng::seed_from_u64(1231275789u64);
let v: Vec<(G1, G1Affine)> = (0..SAMPLES)
.map(|_| (G1::rand(&mut rng), G1::rand(&mut rng).into()))
let v: Vec<($projective, $affine)> = (0..SAMPLES)
.map(|_| {
(
<$projective>::rand(&mut rng),
<$projective>::rand(&mut rng).into(),
)
})
.collect(); .collect();
let mut count = 0; let mut count = 0;
@ -64,13 +69,13 @@ macro_rules! ec_bench {
} }
#[bench] #[bench]
fn bench_g1_double(b: &mut ::test::Bencher) {
fn bench_double(b: &mut ::test::Bencher) {
const SAMPLES: usize = 1000; const SAMPLES: usize = 1000;
let mut rng = XorShiftRng::seed_from_u64(1231275789u64); let mut rng = XorShiftRng::seed_from_u64(1231275789u64);
let v: Vec<(G1, G1)> = (0..SAMPLES)
.map(|_| (G1::rand(&mut rng), G1::rand(&mut rng)))
let v: Vec<($projective, $projective)> = (0..SAMPLES)
.map(|_| (<$projective>::rand(&mut rng), <$projective>::rand(&mut rng)))
.collect(); .collect();
let mut count = 0; let mut count = 0;
@ -83,7 +88,7 @@ macro_rules! ec_bench {
} }
#[bench] #[bench]
fn bench_g1_deser(b: &mut ::test::Bencher) {
fn bench_deser(b: &mut ::test::Bencher) {
use ark_ec::ProjectiveCurve; use ark_ec::ProjectiveCurve;
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
const SAMPLES: usize = 1000; const SAMPLES: usize = 1000;
@ -91,7 +96,7 @@ macro_rules! ec_bench {
let mut rng = XorShiftRng::seed_from_u64(1231275789u64); let mut rng = XorShiftRng::seed_from_u64(1231275789u64);
let mut num_bytes = 0; let mut num_bytes = 0;
let tmp = G1::rand(&mut rng).into_affine();
let tmp = <$projective>::rand(&mut rng).into_affine();
let v: Vec<_> = (0..SAMPLES) let v: Vec<_> = (0..SAMPLES)
.flat_map(|_| { .flat_map(|_| {
let mut bytes = Vec::with_capacity(1000); let mut bytes = Vec::with_capacity(1000);
@ -105,20 +110,22 @@ macro_rules! ec_bench {
b.iter(|| { b.iter(|| {
count = (count + 1) % SAMPLES; count = (count + 1) % SAMPLES;
let index = count * num_bytes; let index = count * num_bytes;
G1Affine::deserialize(&v[index..(index + num_bytes)]).unwrap()
<$affine>::deserialize(&v[index..(index + num_bytes)]).unwrap()
}); });
} }
#[bench] #[bench]
fn bench_g1_ser(b: &mut ::test::Bencher) {
fn bench_ser(b: &mut ::test::Bencher) {
use ark_ec::ProjectiveCurve; use ark_ec::ProjectiveCurve;
use ark_serialize::CanonicalSerialize; use ark_serialize::CanonicalSerialize;
const SAMPLES: usize = 1000; const SAMPLES: usize = 1000;
let mut rng = XorShiftRng::seed_from_u64(1231275789u64); let mut rng = XorShiftRng::seed_from_u64(1231275789u64);
let mut v: Vec<_> = (0..SAMPLES).map(|_| G1::rand(&mut rng)).collect();
let v = G1::batch_normalization_into_affine(v.as_mut_slice());
let mut v: Vec<_> = (0..SAMPLES)
.map(|_| <$projective>::rand(&mut rng))
.collect();
let v = <$projective>::batch_normalization_into_affine(v.as_mut_slice());
let mut bytes = Vec::with_capacity(1000); let mut bytes = Vec::with_capacity(1000);
let mut count = 0; let mut count = 0;
@ -131,7 +138,7 @@ macro_rules! ec_bench {
} }
#[bench] #[bench]
fn bench_g1_deser_unchecked(b: &mut ::test::Bencher) {
fn bench_deser_unchecked(b: &mut ::test::Bencher) {
use ark_ec::ProjectiveCurve; use ark_ec::ProjectiveCurve;
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
const SAMPLES: usize = 1000; const SAMPLES: usize = 1000;
@ -139,7 +146,7 @@ macro_rules! ec_bench {
let mut rng = XorShiftRng::seed_from_u64(1231275789u64); let mut rng = XorShiftRng::seed_from_u64(1231275789u64);
let mut num_bytes = 0; let mut num_bytes = 0;
let tmp = G1::rand(&mut rng).into_affine();
let tmp = <$projective>::rand(&mut rng).into_affine();
let v: Vec<_> = (0..SAMPLES) let v: Vec<_> = (0..SAMPLES)
.flat_map(|_| { .flat_map(|_| {
let mut bytes = Vec::with_capacity(1000); let mut bytes = Vec::with_capacity(1000);
@ -153,196 +160,21 @@ macro_rules! ec_bench {
b.iter(|| { b.iter(|| {
count = (count + 1) % SAMPLES; count = (count + 1) % SAMPLES;
let index = count * num_bytes; let index = count * num_bytes;
G1Affine::deserialize_unchecked(&v[index..(index + num_bytes)]).unwrap()
<$affine>::deserialize_unchecked(&v[index..(index + num_bytes)]).unwrap()
}); });
} }
#[bench] #[bench]
fn bench_g1_ser_unchecked(b: &mut ::test::Bencher) {
fn bench_ser_unchecked(b: &mut ::test::Bencher) {
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
const SAMPLES: usize = 1000; const SAMPLES: usize = 1000;
let mut rng = XorShiftRng::seed_from_u64(1231275789u64); let mut rng = XorShiftRng::seed_from_u64(1231275789u64);
let mut v: Vec<_> = (0..SAMPLES).map(|_| G1::rand(&mut rng)).collect();
let v = G1::batch_normalization_into_affine(v.as_mut_slice());
let mut bytes = Vec::with_capacity(1000);
let mut count = 0;
b.iter(|| {
let tmp = v[count];
count = (count + 1) % SAMPLES;
bytes.clear();
tmp.serialize_unchecked(&mut bytes)
});
}
#[bench]
fn bench_g2_rand(b: &mut ::test::Bencher) {
let mut rng = XorShiftRng::seed_from_u64(1231275789u64);
b.iter(|| G2::rand(&mut rng));
}
#[bench]
fn bench_g2_mul_assign(b: &mut ::test::Bencher) {
const SAMPLES: usize = 1000;
let mut rng = XorShiftRng::seed_from_u64(1231275789u64);
let v: Vec<(G2, Fr)> = (0..SAMPLES)
.map(|_| (G2::rand(&mut rng), Fr::rand(&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_g2_add_assign(b: &mut ::test::Bencher) {
const SAMPLES: usize = 1000;
let mut rng = XorShiftRng::seed_from_u64(1231275789u64);
let v: Vec<(G2, G2)> = (0..SAMPLES)
.map(|_| (G2::rand(&mut rng), G2::rand(&mut rng)))
let mut v: Vec<_> = (0..SAMPLES)
.map(|_| <$projective>::rand(&mut rng))
.collect(); .collect();
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_g2_add_assign_mixed(b: &mut ::test::Bencher) {
const SAMPLES: usize = 1000;
let mut rng = XorShiftRng::seed_from_u64(1231275789u64);
let v: Vec<(G2, G2Affine)> = (0..SAMPLES)
.map(|_| (G2::rand(&mut rng), G2::rand(&mut rng).into()))
.collect();
let mut count = 0;
b.iter(|| {
let mut tmp = v[count].0;
tmp.add_assign_mixed(&v[count].1);
count = (count + 1) % SAMPLES;
tmp
});
}
#[bench]
fn bench_g2_double(b: &mut ::test::Bencher) {
const SAMPLES: usize = 1000;
let mut rng = XorShiftRng::seed_from_u64(1231275789u64);
let v: Vec<(G2, G2)> = (0..SAMPLES)
.map(|_| (G2::rand(&mut rng), G2::rand(&mut rng)))
.collect();
let mut count = 0;
b.iter(|| {
let mut tmp = v[count].0;
tmp.double_in_place();
count = (count + 1) % SAMPLES;
tmp
});
}
#[bench]
fn bench_g2_deser(b: &mut ::test::Bencher) {
use ark_ec::ProjectiveCurve;
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
const SAMPLES: usize = 1000;
let mut rng = XorShiftRng::seed_from_u64(1231275789u64);
let mut num_bytes = 0;
let tmp = G2::rand(&mut rng).into_affine();
let v: Vec<_> = (0..SAMPLES)
.flat_map(|_| {
let mut bytes = Vec::with_capacity(1000);
tmp.serialize(&mut bytes).unwrap();
num_bytes = bytes.len();
bytes
})
.collect();
let mut count = 0;
b.iter(|| {
count = (count + 1) % SAMPLES;
let index = count * num_bytes;
G2Affine::deserialize(&v[index..(index + num_bytes)]).unwrap()
});
}
#[bench]
fn bench_g2_ser(b: &mut ::test::Bencher) {
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
const SAMPLES: usize = 1000;
let mut rng = XorShiftRng::seed_from_u64(1231275789u64);
let mut v: Vec<_> = (0..SAMPLES).map(|_| G2::rand(&mut rng)).collect();
let v = G2::batch_normalization_into_affine(v.as_mut_slice());
let mut bytes = Vec::with_capacity(1000);
let mut count = 0;
b.iter(|| {
let tmp = v[count];
count = (count + 1) % SAMPLES;
bytes.clear();
tmp.serialize(&mut bytes)
});
}
#[bench]
fn bench_g2_deser_unchecked(b: &mut ::test::Bencher) {
use ark_ec::ProjectiveCurve;
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
const SAMPLES: usize = 1000;
let mut rng = XorShiftRng::seed_from_u64(1231275789u64);
let mut num_bytes = 0;
let tmp = G2::rand(&mut rng).into_affine();
let v: Vec<_> = (0..SAMPLES)
.flat_map(|_| {
let mut bytes = Vec::with_capacity(1000);
tmp.serialize_unchecked(&mut bytes).unwrap();
num_bytes = bytes.len();
bytes
})
.collect();
let mut count = 0;
b.iter(|| {
count = (count + 1) % SAMPLES;
let index = count * num_bytes;
G2Affine::deserialize_unchecked(&v[index..(index + num_bytes)]).unwrap()
});
}
#[bench]
fn bench_g2_ser_unchecked(b: &mut ::test::Bencher) {
use ark_ec::ProjectiveCurve;
use ark_serialize::CanonicalSerialize;
const SAMPLES: usize = 1000;
let mut rng = XorShiftRng::seed_from_u64(1231275789u64);
let mut v: Vec<_> = (0..SAMPLES).map(|_| G2::rand(&mut rng)).collect();
let v = G2::batch_normalization_into_affine(v.as_mut_slice());
let v = <$projective>::batch_normalization_into_affine(v.as_mut_slice());
let mut bytes = Vec::with_capacity(1000); let mut bytes = Vec::with_capacity(1000);
let mut count = 0; let mut count = 0;

Loading…
Cancel
Save