Browse Source

Move to `bencher`

fq2_neg_nonresidue
Pratyush Mishra 4 years ago
parent
commit
c6a51adb77
15 changed files with 121 additions and 113 deletions
  1. +1
    -1
      curve-benches/Cargo.toml
  2. +1
    -1
      curve-benches/benches/bls12_377.rs
  3. +1
    -1
      curve-benches/benches/bls12_381.rs
  4. +1
    -1
      curve-benches/benches/bn254.rs
  5. +1
    -1
      curve-benches/benches/bw6_761.rs
  6. +1
    -1
      curve-benches/benches/cp6_782.rs
  7. +1
    -1
      curve-benches/benches/ed_on_bls12_381.rs
  8. +1
    -1
      curve-benches/benches/mnt4_298.rs
  9. +1
    -1
      curve-benches/benches/mnt4_753.rs
  10. +1
    -1
      curve-benches/benches/mnt6_298.rs
  11. +1
    -1
      curve-benches/benches/mnt6_753.rs
  12. +2
    -3
      curve-benches/src/lib.rs
  13. +19
    -29
      curve-benches/src/macros/ec.rs
  14. +81
    -52
      curve-benches/src/macros/field.rs
  15. +8
    -18
      curve-benches/src/macros/pairing.rs

+ 1
- 1
curve-benches/Cargo.toml

@ -38,7 +38,7 @@ ark-bls12-381 = { path = "../bls12_381", optional = true }
ark-ed-on-bls12-381 = { path = "../ed_on_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 }
criterion = { version = "0.3", optional = true }
bencher = { version = "0.1.5" }
paste = { version = "1.0" } paste = { version = "1.0" }
rand = "0.7" rand = "0.7"

+ 1
- 1
curve-benches/benches/bls12_377.rs

@ -31,4 +31,4 @@ f_bench!(target, Fq12, Fq12, fq12);
pairing_bench!(Bls12_377, Fq12); pairing_bench!(Bls12_377, Fq12);
criterion::criterion_main!(g1::group_ops, g2::group_ops, fq, fr, fq2, fq12, pairing);
bencher::benchmark_main!(g1::group_ops, g2::group_ops, fq, fr, fq2, fq12, pairing);

+ 1
- 1
curve-benches/benches/bls12_381.rs

@ -31,4 +31,4 @@ f_bench!(target, Fq12, Fq12, fq12);
pairing_bench!(Bls12_381, Fq12); pairing_bench!(Bls12_381, Fq12);
criterion::criterion_main!(g1::group_ops, g2::group_ops, fq, fr, fq2, fq12, pairing);
bencher::benchmark_main!(g1::group_ops, g2::group_ops, fq, fr, fq2, fq12, pairing);

+ 1
- 1
curve-benches/benches/bn254.rs

@ -31,4 +31,4 @@ f_bench!(target, Fq12, Fq12, fq12);
pairing_bench!(Bn254, Fq12); pairing_bench!(Bn254, Fq12);
criterion::criterion_main!(g1::group_ops, g2::group_ops, fq, fr, fq2, fq12, pairing);
bencher::benchmark_main!(g1::group_ops, g2::group_ops, fq, fr, fq2, fq12, pairing);

+ 1
- 1
curve-benches/benches/bw6_761.rs

@ -30,4 +30,4 @@ f_bench!(Fq, Fq, FqRepr, FqRepr, fq);
f_bench!(Fr, Fr, FrRepr, FrRepr, fr); f_bench!(Fr, Fr, FrRepr, FrRepr, fr);
pairing_bench!(BW6_761, Fq6); pairing_bench!(BW6_761, Fq6);
criterion::criterion_main!(g1::group_ops, g2::group_ops, fq, fr, fq3, fq6, pairing);
bencher::benchmark_main!(g1::group_ops, g2::group_ops, fq, fr, fq3, fq6, pairing);

+ 1
- 1
curve-benches/benches/cp6_782.rs

@ -28,4 +28,4 @@ f_bench!(Fq, Fq, FqRepr, FqRepr, fq);
f_bench!(Fr, Fr, FrRepr, FrRepr, fr); f_bench!(Fr, Fr, FrRepr, FrRepr, fr);
pairing_bench!(CP6_782, Fq6); pairing_bench!(CP6_782, Fq6);
criterion::criterion_main!(g1::group_ops, g2::group_ops, fq, fr, fq3, fq6, pairing);
bencher::benchmark_main!(g1::group_ops, g2::group_ops, fq, fr, fq3, fq6, pairing);

+ 1
- 1
curve-benches/benches/ed_on_bls12_381.rs

@ -18,4 +18,4 @@ mod g {
f_bench!(Fq, Fq, FqRepr, FqRepr, fq); f_bench!(Fq, Fq, FqRepr, FqRepr, fq);
f_bench!(Fr, Fr, FrRepr, FrRepr, fr); f_bench!(Fr, Fr, FrRepr, FrRepr, fr);
criterion::criterion_main!(g::group_ops, fq, fr);
bencher::benchmark_main!(g::group_ops, fq, fr);

+ 1
- 1
curve-benches/benches/mnt4_298.rs

@ -30,4 +30,4 @@ f_bench!(Fq, Fq, FqRepr, FqRepr, fq);
f_bench!(Fr, Fr, FqRepr, FqRepr, fr); f_bench!(Fr, Fr, FqRepr, FqRepr, fr);
pairing_bench!(MNT4_298, Fq4); pairing_bench!(MNT4_298, Fq4);
criterion::criterion_main!(g1::group_ops, g2::group_ops, fq, fr, fq2, fq4, pairing);
bencher::benchmark_main!(g1::group_ops, g2::group_ops, fq, fr, fq2, fq4, pairing);

+ 1
- 1
curve-benches/benches/mnt4_753.rs

@ -30,4 +30,4 @@ f_bench!(Fq, Fq, FqRepr, FqRepr, fq);
f_bench!(Fr, Fr, FqRepr, FqRepr, fr); f_bench!(Fr, Fr, FqRepr, FqRepr, fr);
pairing_bench!(MNT4_753, Fq4); pairing_bench!(MNT4_753, Fq4);
criterion::criterion_main!(g1::group_ops, g2::group_ops, fq, fr, fq2, fq4, pairing);
bencher::benchmark_main!(g1::group_ops, g2::group_ops, fq, fr, fq2, fq4, pairing);

+ 1
- 1
curve-benches/benches/mnt6_298.rs

@ -30,4 +30,4 @@ f_bench!(Fq, Fq, FqRepr, FqRepr, fq);
f_bench!(Fr, Fr, FqRepr, FqRepr, fr); f_bench!(Fr, Fr, FqRepr, FqRepr, fr);
pairing_bench!(MNT6_298, Fq6); pairing_bench!(MNT6_298, Fq6);
criterion::criterion_main!(g1::group_ops, g2::group_ops, fq, fr, fq3, fq6, pairing);
bencher::benchmark_main!(g1::group_ops, g2::group_ops, fq, fr, fq3, fq6, pairing);

+ 1
- 1
curve-benches/benches/mnt6_753.rs

@ -30,4 +30,4 @@ f_bench!(Fq, Fq, FqRepr, FqRepr, fq);
f_bench!(Fr, Fr, FqRepr, FqRepr, fr); f_bench!(Fr, Fr, FqRepr, FqRepr, fr);
pairing_bench!(MNT6_753, Fq6); pairing_bench!(MNT6_753, Fq6);
criterion::criterion_main!(g1::group_ops, g2::group_ops, fq, fr, fq3, fq6, pairing);
bencher::benchmark_main!(g1::group_ops, g2::group_ops, fq, fr, fq3, fq6, pairing);

+ 2
- 3
curve-benches/src/lib.rs

@ -3,10 +3,9 @@
pub mod macros; pub mod macros;
pub use macros::*; pub use macros::*;
#[cfg(feature = "criterion")]
#[macro_use] #[macro_use]
pub extern crate criterion;
pub use criterion::*;
pub extern crate bencher;
pub use bencher::*;
#[macro_use] #[macro_use]
pub extern crate paste; pub extern crate paste;

+ 19
- 29
curve-benches/src/macros/ec.rs

@ -1,26 +1,13 @@
#[macro_export] #[macro_export]
macro_rules! ec_bench { macro_rules! ec_bench {
($projective:ty, $affine:ty) => { ($projective:ty, $affine:ty) => {
fn bench_curve(c: &mut $crate::criterion::Criterion) {
let mut group = c.benchmark_group("Group operation benchmarks for ".to_string() + core::stringify!($projective));
group.bench_function("Rand", rand);
group.bench_function("MulAssign", mul_assign);
group.bench_function("AddAssign", add_assign);
group.bench_function("AddAssignMixed", add_assign_mixed);
group.bench_function("Serialize w/ compression", ser);
group.bench_function("Deserialize w/ compression", deser);
group.bench_function("Serialize unchecked", ser_unchecked);
group.bench_function("Deserialize unchecked", deser_unchecked);
}
fn rand(b: &mut $crate::criterion::Bencher) {
fn rand(b: &mut $crate::bencher::Bencher) {
let mut rng = XorShiftRng::seed_from_u64(1231275789u64); let mut rng = XorShiftRng::seed_from_u64(1231275789u64);
b.iter(|| <$projective>::rand(&mut rng)); b.iter(|| <$projective>::rand(&mut rng));
} }
fn mul_assign(b: &mut $crate::criterion::Bencher) {
fn mul_assign(b: &mut $crate::bencher::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);
@ -39,7 +26,7 @@ macro_rules! ec_bench {
} }
fn add_assign(b: &mut $crate::criterion::Bencher) {
fn add_assign(b: &mut $crate::bencher::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);
@ -58,7 +45,7 @@ macro_rules! ec_bench {
} }
fn add_assign_mixed(b: &mut $crate::criterion::Bencher) {
fn add_assign_mixed(b: &mut $crate::bencher::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);
@ -82,7 +69,7 @@ macro_rules! ec_bench {
} }
fn double(b: &mut $crate::criterion::Bencher) {
fn double(b: &mut $crate::bencher::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);
@ -101,7 +88,7 @@ macro_rules! ec_bench {
} }
fn deser(b: &mut $crate::criterion::Bencher) {
fn deser(b: &mut $crate::bencher::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;
@ -128,7 +115,7 @@ macro_rules! ec_bench {
} }
fn ser(b: &mut $crate::criterion::Bencher) {
fn ser(b: &mut $crate::bencher::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;
@ -151,7 +138,7 @@ macro_rules! ec_bench {
} }
fn deser_unchecked(b: &mut $crate::criterion::Bencher) {
fn deser_unchecked(b: &mut $crate::bencher::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;
@ -178,7 +165,7 @@ macro_rules! ec_bench {
} }
fn ser_unchecked(b: &mut $crate::criterion::Bencher) {
fn ser_unchecked(b: &mut $crate::bencher::Bencher) {
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
const SAMPLES: usize = 1000; const SAMPLES: usize = 1000;
@ -199,13 +186,16 @@ macro_rules! ec_bench {
}); });
} }
$crate::criterion::criterion_group!(
name = group_ops;
config = $crate::criterion::Criterion::default()
.sample_size(10)
.warm_up_time(core::time::Duration::from_millis(500))
.measurement_time(core::time::Duration::from_secs(1));
targets = bench_curve,
$crate::bencher::benchmark_group!(
group_ops,
rand,
mul_assign,
add_assign,
add_assign_mixed,
ser,
deser,
ser_unchecked,
deser_unchecked,
); );
}; };
} }

+ 81
- 52
curve-benches/src/macros/field.rs

@ -8,8 +8,33 @@ macro_rules! f_bench {
field_common!($f, $f_type); field_common!($f, $f_type);
sqrt!($f, $f_type); sqrt!($f, $f_type);
prime_field!($f, $f_type, $f_repr, $f_repr_type); prime_field!($f, $f_type, $f_repr, $f_repr_type);
$crate::bencher::benchmark_group!(
$modname,
// common stuff
add_assign,
sub_assign,
double,
negate,
mul_assign,
square,
inverse,
ser,
deser,
ser_unchecked,
deser_unchecked,
// sqrt field stuff
sqrt,
// prime field stuff
repr_add_nocarry,
repr_sub_noborrow,
repr_num_bits,
repr_mul2,
repr_div2,
into_repr,
from_repr,
);
} }
$crate::criterion::criterion_group!($modname, [<_ $modname>]::bench_common_field_ops, [<_ $modname>]::bench_sqrt, [<_ $modname>]::bench_prime_field_ops);
use [<_ $modname>]::$modname;
} }
}; };
// use this for intermediate fields // use this for intermediate fields
@ -19,8 +44,25 @@ macro_rules! f_bench {
use super::*; use super::*;
field_common!($f, $f_type); field_common!($f, $f_type);
sqrt!($f, $f_type); sqrt!($f, $f_type);
$crate::bencher::benchmark_group!(
$modname,
// common stuff
add_assign,
sub_assign,
double,
negate,
mul_assign,
square,
inverse,
ser,
deser,
ser_unchecked,
deser_unchecked,
// sqrt field stuff
sqrt,
);
} }
$crate::criterion::criterion_group!($modname, [<_ $modname>]::bench_common_field_ops, [<_ $modname>]::bench_sqrt);
use [<_ $modname>]::$modname;
} }
}; };
// Use this for the full extension field Fqk // Use this for the full extension field Fqk
@ -29,8 +71,23 @@ macro_rules! f_bench {
mod [<_ $modname>] { mod [<_ $modname>] {
use super::*; use super::*;
field_common!($f, $f_type); field_common!($f, $f_type);
$crate::bencher::benchmark_group!(
$modname,
// common stuff
add_assign,
sub_assign,
double,
negate,
mul_assign,
square,
inverse,
ser,
deser,
ser_unchecked,
deser_unchecked,
);
} }
$crate::criterion::criterion_group!($modname, [<_ $modname>]::bench_common_field_ops);
use [<_ $modname>]::$modname;
} }
}; };
} }
@ -38,22 +95,7 @@ macro_rules! f_bench {
#[macro_export] #[macro_export]
macro_rules! field_common { macro_rules! field_common {
($f:ident, $f_type:ty) => { ($f:ident, $f_type:ty) => {
pub fn bench_common_field_ops(c: &mut $crate::criterion::Criterion) {
let mut group = c.benchmark_group("Common field operations for ".to_string() + core::stringify!($f));
group.bench_function("AddAssign", add_assign);
group.bench_function("SubAssign", sub_assign);
group.bench_function("Double", double);
group.bench_function("Negate", negate);
group.bench_function("MulAssign", mul_assign);
group.bench_function("Square", square);
group.bench_function("Inverse", inverse);
group.bench_function("Serialize w/ compression", ser);
group.bench_function("Deserialize w/ compression", deser);
group.bench_function("Serialize unchecked", ser_unchecked);
group.bench_function("Deserialize unchecked", deser_unchecked);
}
fn add_assign(b: &mut $crate::criterion::Bencher) {
fn add_assign(b: &mut $crate::bencher::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);
@ -72,7 +114,7 @@ macro_rules! field_common {
} }
fn sub_assign(b: &mut $crate::criterion::Bencher) {
fn sub_assign(b: &mut $crate::bencher::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);
@ -90,7 +132,7 @@ macro_rules! field_common {
}); });
} }
fn double(b: &mut $crate::criterion::Bencher) {
fn double(b: &mut $crate::bencher::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);
@ -107,7 +149,7 @@ macro_rules! field_common {
} }
fn negate(b: &mut $crate::criterion::Bencher) {
fn negate(b: &mut $crate::bencher::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);
@ -123,7 +165,7 @@ macro_rules! field_common {
}); });
} }
fn mul_assign(b: &mut $crate::criterion::Bencher) {
fn mul_assign(b: &mut $crate::bencher::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);
@ -141,7 +183,7 @@ macro_rules! field_common {
}); });
} }
fn square(b: &mut $crate::criterion::Bencher) {
fn square(b: &mut $crate::bencher::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);
@ -158,7 +200,7 @@ macro_rules! field_common {
} }
fn inverse(b: &mut $crate::criterion::Bencher) {
fn inverse(b: &mut $crate::bencher::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);
@ -174,7 +216,7 @@ macro_rules! field_common {
} }
fn deser(b: &mut $crate::criterion::Bencher) {
fn deser(b: &mut $crate::bencher::Bencher) {
use ark_serialize::{CanonicalSerialize, CanonicalDeserialize}; use ark_serialize::{CanonicalSerialize, CanonicalDeserialize};
const SAMPLES: usize = 1000; const SAMPLES: usize = 1000;
@ -198,7 +240,7 @@ macro_rules! field_common {
} }
fn ser(b: &mut $crate::criterion::Bencher) {
fn ser(b: &mut $crate::bencher::Bencher) {
use ark_serialize::CanonicalSerialize; use ark_serialize::CanonicalSerialize;
const SAMPLES: usize = 1000; const SAMPLES: usize = 1000;
@ -218,7 +260,7 @@ macro_rules! field_common {
} }
fn deser_unchecked(b: &mut $crate::criterion::Bencher) {
fn deser_unchecked(b: &mut $crate::bencher::Bencher) {
use ark_serialize::{CanonicalSerialize, CanonicalDeserialize}; use ark_serialize::{CanonicalSerialize, CanonicalDeserialize};
const SAMPLES: usize = 1000; const SAMPLES: usize = 1000;
@ -242,7 +284,7 @@ macro_rules! field_common {
} }
fn ser_unchecked(b: &mut $crate::criterion::Bencher) {
fn ser_unchecked(b: &mut $crate::bencher::Bencher) {
use ark_serialize::CanonicalSerialize; use ark_serialize::CanonicalSerialize;
const SAMPLES: usize = 1000; const SAMPLES: usize = 1000;
@ -266,7 +308,7 @@ macro_rules! field_common {
#[macro_export] #[macro_export]
macro_rules! sqrt { macro_rules! sqrt {
($f:ident, $f_type:ty) => { ($f:ident, $f_type:ty) => {
pub fn bench_sqrt(b: &mut $crate::criterion::Criterion) {
pub fn sqrt(b: &mut $crate::bencher::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);
@ -280,11 +322,9 @@ macro_rules! sqrt {
.collect(); .collect();
let mut count = 0; let mut count = 0;
b.bench_function(
core::concat!("Square-roots for ", core::stringify!($f)),
|_| {
b.iter(|| {
count = (count + 1) % SAMPLES; count = (count + 1) % SAMPLES;
let _ = v[count].sqrt();
v[count].sqrt()
}); });
} }
} }
@ -293,18 +333,7 @@ macro_rules! sqrt {
#[macro_export] #[macro_export]
macro_rules! prime_field { macro_rules! prime_field {
($f:ident, $f_type:ty, $f_repr:ident, $f_repr_type:ty) => { ($f:ident, $f_type:ty, $f_repr:ident, $f_repr_type:ty) => {
pub fn bench_prime_field_ops(c: &mut $crate::criterion::Criterion) {
let mut group = c.benchmark_group("Prime field operations for ".to_string() + core::stringify!($f));
group.bench_function("AddNoCarry for BigInteger", repr_add_nocarry);
group.bench_function("SubNoBorrow for BigInteger", repr_sub_noborrow);
group.bench_function("NumBits for BigInteger", repr_num_bits);
group.bench_function("MulBy2 for BigInteger", repr_mul2);
group.bench_function("DivBy2 for BigInteger", repr_div2);
group.bench_function("Into BigInteger", into_repr);
group.bench_function("From BigInteger", from_repr);
}
fn repr_add_nocarry(b: &mut $crate::criterion::Bencher) {
fn repr_add_nocarry(b: &mut $crate::bencher::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);
@ -331,7 +360,7 @@ macro_rules! prime_field {
}); });
} }
fn repr_sub_noborrow(b: &mut $crate::criterion::Bencher) {
fn repr_sub_noborrow(b: &mut $crate::bencher::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);
@ -357,7 +386,7 @@ macro_rules! prime_field {
}); });
} }
fn repr_num_bits(b: &mut $crate::criterion::Bencher) {
fn repr_num_bits(b: &mut $crate::bencher::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);
@ -372,7 +401,7 @@ macro_rules! prime_field {
}); });
} }
fn repr_mul2(b: &mut $crate::criterion::Bencher) {
fn repr_mul2(b: &mut $crate::bencher::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);
@ -388,7 +417,7 @@ macro_rules! prime_field {
}); });
} }
fn repr_div2(b: &mut $crate::criterion::Bencher) {
fn repr_div2(b: &mut $crate::bencher::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);
@ -404,7 +433,7 @@ macro_rules! prime_field {
}); });
} }
fn into_repr(b: &mut $crate::criterion::Bencher) {
fn into_repr(b: &mut $crate::bencher::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);
@ -418,7 +447,7 @@ macro_rules! prime_field {
}); });
} }
fn from_repr(b: &mut $crate::criterion::Bencher) {
fn from_repr(b: &mut $crate::bencher::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);

+ 8
- 18
curve-benches/src/macros/pairing.rs

@ -1,15 +1,7 @@
#[macro_export] #[macro_export]
macro_rules! pairing_bench { macro_rules! pairing_bench {
($curve:ident, $pairing_field:ident) => { ($curve:ident, $pairing_field:ident) => {
fn bench_pairing(c: &mut $crate::criterion::Criterion) {
let mut group = c.benchmark_group("Pairing for ".to_string() + core::stringify!($curve));
group.bench_function("Miller Loop", miller_loop);
group.bench_function("Final Exponentiation", final_exponentiation);
group.bench_function("Full Pairing", full_pairing);
}
fn miller_loop(b: &mut $crate::criterion::Bencher) {
fn miller_loop(b: &mut $crate::bencher::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);
@ -32,7 +24,7 @@ macro_rules! pairing_bench {
} }
fn final_exponentiation(b: &mut $crate::criterion::Bencher) {
fn final_exponentiation(b: &mut $crate::bencher::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);
@ -56,7 +48,7 @@ macro_rules! pairing_bench {
} }
fn full_pairing(b: &mut $crate::criterion::Bencher) {
fn full_pairing(b: &mut $crate::bencher::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);
@ -73,13 +65,11 @@ macro_rules! pairing_bench {
}); });
} }
$crate::criterion::criterion_group!(
name = pairing;
config = $crate::criterion::Criterion::default()
.sample_size(10)
.warm_up_time(core::time::Duration::from_millis(500))
.measurement_time(core::time::Duration::from_secs(1));
targets = bench_pairing,
$crate::bencher::benchmark_group!(
pairing,
miller_loop,
final_exponentiation,
full_pairing,
); );
} }
} }

Loading…
Cancel
Save