From c4e4e18dee0702c47ca85349f74f0753e6130ab5 Mon Sep 17 00:00:00 2001 From: Pratyush Mishra Date: Wed, 11 Nov 2020 20:31:51 -0800 Subject: [PATCH] Fix benchmark compilation and add benchmarks for Edwards curves --- curve-benches/Cargo.toml | 3 +- curve-benches/src/curves/bls12_377.rs | 12 +- curve-benches/src/curves/bls12_381.rs | 12 +- curve-benches/src/curves/bn254.rs | 20 +- curve-benches/src/curves/bw6_761.rs | 12 +- curve-benches/src/curves/cp6_782.rs | 12 +- curve-benches/src/curves/ed_on_bls12_381.rs | 18 ++ curve-benches/src/curves/mnt4_298.rs | 12 +- curve-benches/src/curves/mnt4_753.rs | 12 +- curve-benches/src/curves/mnt6_298.rs | 12 +- curve-benches/src/curves/mnt6_753.rs | 12 +- curve-benches/src/curves/mod.rs | 20 +- curve-benches/src/macros/ec.rs | 238 +++----------------- 13 files changed, 160 insertions(+), 235 deletions(-) create mode 100644 curve-benches/src/curves/ed_on_bls12_381.rs diff --git a/curve-benches/Cargo.toml b/curve-benches/Cargo.toml index cbae12f..b17061b 100644 --- a/curve-benches/Cargo.toml +++ b/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-mnt4-753 = { path = "../mnt4_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-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-cp6-782 = { path = "../cp6_782", optional = true } diff --git a/curve-benches/src/curves/bls12_377.rs b/curve-benches/src/curves/bls12_377.rs index 3e7ea3c..c198c25 100644 --- a/curve-benches/src/curves/bls12_377.rs +++ b/curve-benches/src/curves/bls12_377.rs @@ -2,7 +2,7 @@ use rand::SeedableRng; use rand_xorshift::XorShiftRng; 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, G2Projective as G2, Parameters, }; @@ -15,7 +15,15 @@ use ark_ff::{ 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!(2, Fq12, Fq12, fq12); f_bench!(Fq, Fq, FqRepr, FqRepr, fq); diff --git a/curve-benches/src/curves/bls12_381.rs b/curve-benches/src/curves/bls12_381.rs index 2b5e2ce..cd58eb4 100644 --- a/curve-benches/src/curves/bls12_381.rs +++ b/curve-benches/src/curves/bls12_381.rs @@ -2,7 +2,7 @@ use rand::SeedableRng; use rand_xorshift::XorShiftRng; 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, G2Projective as G2, Parameters, }; @@ -15,7 +15,15 @@ use ark_ff::{ 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!(2, Fq12, Fq12, fq12); f_bench!(Fq, Fq, FqRepr, FqRepr, fq); diff --git a/curve-benches/src/curves/bn254.rs b/curve-benches/src/curves/bn254.rs index 9ef4b83..e430ffb 100644 --- a/curve-benches/src/curves/bn254.rs +++ b/curve-benches/src/curves/bn254.rs @@ -2,20 +2,28 @@ use rand::SeedableRng; use rand_xorshift::XorShiftRng; 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::{ bn::{G1Prepared, G2Prepared}, PairingEngine, ProjectiveCurve, }; -use ark_ef::{ +use ark_ff::{ biginteger::{BigInteger256 as FrRepr, BigInteger256 as FqRepr}, 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!(2, Fq12, Fq12, fq12); f_bench!(Fq, Fq, FqRepr, FqRepr, fq); diff --git a/curve-benches/src/curves/bw6_761.rs b/curve-benches/src/curves/bw6_761.rs index e0ec223..e342500 100644 --- a/curve-benches/src/curves/bw6_761.rs +++ b/curve-benches/src/curves/bw6_761.rs @@ -2,7 +2,7 @@ use rand::SeedableRng; use rand_xorshift::XorShiftRng; 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, Parameters, BW6_761, }; @@ -15,7 +15,15 @@ use ark_ff::{ 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!(2, Fq6, Fq6, fq6); f_bench!(Fq, Fq, FqRepr, FqRepr, fq); diff --git a/curve-benches/src/curves/cp6_782.rs b/curve-benches/src/curves/cp6_782.rs index ca3f5da..b343c57 100644 --- a/curve-benches/src/curves/cp6_782.rs +++ b/curve-benches/src/curves/cp6_782.rs @@ -2,7 +2,7 @@ use rand::SeedableRng; use rand_xorshift::XorShiftRng; 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, CP6_782, }; @@ -12,7 +12,15 @@ use ark_ff::{ 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!(2, Fq6, Fq6, fq6); f_bench!(Fq, Fq, FqRepr, FqRepr, fq); diff --git a/curve-benches/src/curves/ed_on_bls12_381.rs b/curve-benches/src/curves/ed_on_bls12_381.rs new file mode 100644 index 0000000..6685b0c --- /dev/null +++ b/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); diff --git a/curve-benches/src/curves/mnt4_298.rs b/curve-benches/src/curves/mnt4_298.rs index 9b47966..cc0d027 100644 --- a/curve-benches/src/curves/mnt4_298.rs +++ b/curve-benches/src/curves/mnt4_298.rs @@ -10,12 +10,20 @@ use ark_ff::{ biginteger::BigInteger320 as FqRepr, BigInteger, Field, PrimeField, SquareRootField, 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, 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!(2, Fq4, Fq4, fq4); f_bench!(Fq, Fq, FqRepr, FqRepr, fq); diff --git a/curve-benches/src/curves/mnt4_753.rs b/curve-benches/src/curves/mnt4_753.rs index d83d4f9..f493018 100644 --- a/curve-benches/src/curves/mnt4_753.rs +++ b/curve-benches/src/curves/mnt4_753.rs @@ -10,12 +10,20 @@ use ark_ff::{ biginteger::BigInteger768 as FqRepr, BigInteger, Field, PrimeField, SquareRootField, 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, 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!(2, Fq4, Fq4, fq4); f_bench!(Fq, Fq, FqRepr, FqRepr, fq); diff --git a/curve-benches/src/curves/mnt6_298.rs b/curve-benches/src/curves/mnt6_298.rs index 30dd06f..45c229f 100644 --- a/curve-benches/src/curves/mnt6_298.rs +++ b/curve-benches/src/curves/mnt6_298.rs @@ -10,12 +10,20 @@ use ark_ff::{ biginteger::BigInteger320 as FqRepr, BigInteger, Field, PrimeField, SquareRootField, 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, 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!(2, Fq6, Fq6, fq6); f_bench!(Fq, Fq, FqRepr, FqRepr, fq); diff --git a/curve-benches/src/curves/mnt6_753.rs b/curve-benches/src/curves/mnt6_753.rs index 77c57b0..87605e9 100644 --- a/curve-benches/src/curves/mnt6_753.rs +++ b/curve-benches/src/curves/mnt6_753.rs @@ -10,12 +10,20 @@ use ark_ff::{ biginteger::BigInteger768 as FqRepr, BigInteger, Field, PrimeField, SquareRootField, 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, 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!(2, Fq6, Fq6, fq6); f_bench!(Fq, Fq, FqRepr, FqRepr, fq); diff --git a/curve-benches/src/curves/mod.rs b/curve-benches/src/curves/mod.rs index 3a1dab9..48f3a4c 100644 --- a/curve-benches/src/curves/mod.rs +++ b/curve-benches/src/curves/mod.rs @@ -1,18 +1,20 @@ -#[cfg(feature = "bls12_377")] +#[cfg(feature = "ark-bls12-377")] mod bls12_377; -#[cfg(feature = "bls12_381")] +#[cfg(feature = "ark-bls12-381")] mod bls12_381; -#[cfg(feature = "bn254")] +#[cfg(feature = "ark-bn254")] mod bn254; -#[cfg(feature = "bw6_761")] +#[cfg(feature = "ark-bw6-761")] mod bw6_761; -#[cfg(feature = "cp6_782")] +#[cfg(feature = "ark-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; -#[cfg(feature = "mnt4_753")] +#[cfg(feature = "ark-mnt4-753")] mod mnt4_753; -#[cfg(feature = "mnt6_298")] +#[cfg(feature = "ark-mnt6-298")] mod mnt6_298; -#[cfg(feature = "mnt6_753")] +#[cfg(feature = "ark-mnt6-753")] mod mnt6_753; diff --git a/curve-benches/src/macros/ec.rs b/curve-benches/src/macros/ec.rs index 99c5288..eb6277c 100644 --- a/curve-benches/src/macros/ec.rs +++ b/curve-benches/src/macros/ec.rs @@ -1,19 +1,19 @@ macro_rules! ec_bench { - () => { + ($projective:ty, $affine:ty) => { #[bench] - fn bench_g1_rand(b: &mut ::test::Bencher) { + fn bench_rand(b: &mut ::test::Bencher) { let mut rng = XorShiftRng::seed_from_u64(1231275789u64); - b.iter(|| G1::rand(&mut rng)); + b.iter(|| <$projective>::rand(&mut rng)); } #[bench] - fn bench_g1_mul_assign(b: &mut ::test::Bencher) { + fn bench_mul_assign(b: &mut ::test::Bencher) { const SAMPLES: usize = 1000; 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(); let mut count = 0; @@ -26,13 +26,13 @@ macro_rules! ec_bench { } #[bench] - fn bench_g1_add_assign(b: &mut ::test::Bencher) { + fn bench_add_assign(b: &mut ::test::Bencher) { const SAMPLES: usize = 1000; 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(); let mut count = 0; @@ -45,13 +45,18 @@ macro_rules! ec_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; 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(); let mut count = 0; @@ -64,13 +69,13 @@ macro_rules! ec_bench { } #[bench] - fn bench_g1_double(b: &mut ::test::Bencher) { + fn bench_double(b: &mut ::test::Bencher) { const SAMPLES: usize = 1000; 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(); let mut count = 0; @@ -83,7 +88,7 @@ macro_rules! ec_bench { } #[bench] - fn bench_g1_deser(b: &mut ::test::Bencher) { + fn bench_deser(b: &mut ::test::Bencher) { use ark_ec::ProjectiveCurve; use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; const SAMPLES: usize = 1000; @@ -91,7 +96,7 @@ macro_rules! ec_bench { let mut rng = XorShiftRng::seed_from_u64(1231275789u64); 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) .flat_map(|_| { let mut bytes = Vec::with_capacity(1000); @@ -105,20 +110,22 @@ macro_rules! ec_bench { b.iter(|| { count = (count + 1) % SAMPLES; let index = count * num_bytes; - G1Affine::deserialize(&v[index..(index + num_bytes)]).unwrap() + <$affine>::deserialize(&v[index..(index + num_bytes)]).unwrap() }); } #[bench] - fn bench_g1_ser(b: &mut ::test::Bencher) { + fn bench_ser(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(|_| 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 count = 0; @@ -131,7 +138,7 @@ macro_rules! ec_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_serialize::{CanonicalDeserialize, CanonicalSerialize}; const SAMPLES: usize = 1000; @@ -139,7 +146,7 @@ macro_rules! ec_bench { let mut rng = XorShiftRng::seed_from_u64(1231275789u64); 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) .flat_map(|_| { let mut bytes = Vec::with_capacity(1000); @@ -153,196 +160,21 @@ macro_rules! ec_bench { b.iter(|| { count = (count + 1) % SAMPLES; let index = count * num_bytes; - G1Affine::deserialize_unchecked(&v[index..(index + num_bytes)]).unwrap() + <$affine>::deserialize_unchecked(&v[index..(index + num_bytes)]).unwrap() }); } #[bench] - fn bench_g1_ser_unchecked(b: &mut ::test::Bencher) { + fn bench_ser_unchecked(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(|_| 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(); - - 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 count = 0;