Skip to content

Commit

Permalink
Move to bencher
Browse files Browse the repository at this point in the history
  • Loading branch information
Pratyush committed Dec 11, 2020
1 parent 4ab7431 commit c6a51ad
Show file tree
Hide file tree
Showing 15 changed files with 121 additions and 113 deletions.
2 changes: 1 addition & 1 deletion curve-benches/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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-bw6-761 = { path = "../bw6_761", 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" }

rand = "0.7"
Expand Down
2 changes: 1 addition & 1 deletion curve-benches/benches/bls12_377.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ f_bench!(target, Fq12, Fq12, 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);
2 changes: 1 addition & 1 deletion curve-benches/benches/bls12_381.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ f_bench!(target, Fq12, Fq12, 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);
2 changes: 1 addition & 1 deletion curve-benches/benches/bn254.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ f_bench!(target, Fq12, Fq12, 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);
2 changes: 1 addition & 1 deletion curve-benches/benches/bw6_761.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ f_bench!(Fq, Fq, FqRepr, FqRepr, fq);
f_bench!(Fr, Fr, FrRepr, FrRepr, fr);
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);
2 changes: 1 addition & 1 deletion curve-benches/benches/cp6_782.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ f_bench!(Fq, Fq, FqRepr, FqRepr, fq);
f_bench!(Fr, Fr, FrRepr, FrRepr, fr);
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);
2 changes: 1 addition & 1 deletion curve-benches/benches/ed_on_bls12_381.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ mod g {
f_bench!(Fq, Fq, FqRepr, FqRepr, fq);
f_bench!(Fr, Fr, FrRepr, FrRepr, fr);

criterion::criterion_main!(g::group_ops, fq, fr);
bencher::benchmark_main!(g::group_ops, fq, fr);
2 changes: 1 addition & 1 deletion curve-benches/benches/mnt4_298.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ f_bench!(Fq, Fq, FqRepr, FqRepr, fq);
f_bench!(Fr, Fr, FqRepr, FqRepr, fr);
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);
2 changes: 1 addition & 1 deletion curve-benches/benches/mnt4_753.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ f_bench!(Fq, Fq, FqRepr, FqRepr, fq);
f_bench!(Fr, Fr, FqRepr, FqRepr, fr);
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);
2 changes: 1 addition & 1 deletion curve-benches/benches/mnt6_298.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ f_bench!(Fq, Fq, FqRepr, FqRepr, fq);
f_bench!(Fr, Fr, FqRepr, FqRepr, fr);
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);
2 changes: 1 addition & 1 deletion curve-benches/benches/mnt6_753.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ f_bench!(Fq, Fq, FqRepr, FqRepr, fq);
f_bench!(Fr, Fr, FqRepr, FqRepr, fr);
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);
5 changes: 2 additions & 3 deletions curve-benches/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
pub mod macros;
pub use macros::*;

#[cfg(feature = "criterion")]
#[macro_use]
pub extern crate criterion;
pub use criterion::*;
pub extern crate bencher;
pub use bencher::*;

#[macro_use]
pub extern crate paste;
Expand Down
48 changes: 19 additions & 29 deletions curve-benches/src/macros/ec.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,13 @@
#[macro_export]
macro_rules! ec_bench {
($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);
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;

let mut rng = XorShiftRng::seed_from_u64(1231275789u64);
Expand All @@ -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;

let mut rng = XorShiftRng::seed_from_u64(1231275789u64);
Expand All @@ -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;

let mut rng = XorShiftRng::seed_from_u64(1231275789u64);
Expand All @@ -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;

let mut rng = XorShiftRng::seed_from_u64(1231275789u64);
Expand All @@ -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_serialize::{CanonicalDeserialize, CanonicalSerialize};
const SAMPLES: usize = 1000;
Expand All @@ -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_serialize::CanonicalSerialize;
const SAMPLES: usize = 1000;
Expand All @@ -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_serialize::{CanonicalDeserialize, CanonicalSerialize};
const SAMPLES: usize = 1000;
Expand All @@ -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};
const SAMPLES: usize = 1000;

Expand All @@ -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,
);
};
}
Loading

0 comments on commit c6a51ad

Please sign in to comment.