Migrate jubjub benchmarks to criterion
This commit is contained in:
parent
f44556d7bf
commit
7ea1da5d6f
|
@ -493,6 +493,7 @@ name = "jubjub"
|
|||
version = "0.3.0"
|
||||
dependencies = [
|
||||
"bls12_381 0.1.0",
|
||||
"criterion 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand_xorshift 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"subtle 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
|
|
@ -22,6 +22,9 @@ default-features = false
|
|||
version = "^2.2.1"
|
||||
default-features = false
|
||||
|
||||
[dev-dependencies]
|
||||
criterion = "0.3"
|
||||
|
||||
[dev-dependencies.rand_core]
|
||||
version = "0.5"
|
||||
default-features = false
|
||||
|
@ -32,3 +35,15 @@ default-features = false
|
|||
|
||||
[features]
|
||||
default = []
|
||||
|
||||
[[bench]]
|
||||
name = "fq_bench"
|
||||
harness = false
|
||||
|
||||
[[bench]]
|
||||
name = "fr_bench"
|
||||
harness = false
|
||||
|
||||
[[bench]]
|
||||
name = "point_bench"
|
||||
harness = false
|
||||
|
|
|
@ -1,51 +1,58 @@
|
|||
#![feature(test)]
|
||||
|
||||
extern crate test;
|
||||
|
||||
use criterion::{criterion_group, criterion_main, Criterion};
|
||||
use jubjub::*;
|
||||
use test::Bencher;
|
||||
|
||||
#[bench]
|
||||
fn bench_mul_assign(bencher: &mut Bencher) {
|
||||
fn bench_add_assign(c: &mut Criterion) {
|
||||
let mut n = Fq::one();
|
||||
let b = -Fq::one();
|
||||
bencher.iter(move || {
|
||||
n *= &b;
|
||||
let neg_one = -Fq::one();
|
||||
c.bench_function("Fq add_assign", |b| {
|
||||
b.iter(move || {
|
||||
n += &neg_one;
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_sub_assign(bencher: &mut Bencher) {
|
||||
fn bench_sub_assign(c: &mut Criterion) {
|
||||
let mut n = Fq::one();
|
||||
let b = -Fq::one();
|
||||
bencher.iter(move || {
|
||||
n -= &b;
|
||||
let neg_one = -Fq::one();
|
||||
c.bench_function("Fq sub_assign", |b| {
|
||||
b.iter(move || {
|
||||
n -= &neg_one;
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_add_assign(bencher: &mut Bencher) {
|
||||
fn bench_mul_assign(c: &mut Criterion) {
|
||||
let mut n = Fq::one();
|
||||
let b = -Fq::one();
|
||||
bencher.iter(move || {
|
||||
n += &b;
|
||||
let neg_one = -Fq::one();
|
||||
c.bench_function("Fq mul_assign", |b| {
|
||||
b.iter(move || {
|
||||
n *= &neg_one;
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_square_assign(bencher: &mut Bencher) {
|
||||
fn bench_square(c: &mut Criterion) {
|
||||
let n = Fq::one();
|
||||
bencher.iter(move || n.square());
|
||||
c.bench_function("Fq square", |b| b.iter(move || n.square()));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_invert(bencher: &mut Bencher) {
|
||||
fn bench_invert(c: &mut Criterion) {
|
||||
let n = Fq::one();
|
||||
bencher.iter(move || n.invert());
|
||||
c.bench_function("Fq invert", |b| b.iter(move || n.invert()));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_sqrt(bencher: &mut Bencher) {
|
||||
fn bench_sqrt(c: &mut Criterion) {
|
||||
let n = Fq::one().double().double();
|
||||
bencher.iter(move || n.sqrt());
|
||||
c.bench_function("Fq sqrt", |b| b.iter(move || n.sqrt()));
|
||||
}
|
||||
|
||||
criterion_group!(
|
||||
benches,
|
||||
bench_add_assign,
|
||||
bench_sub_assign,
|
||||
bench_mul_assign,
|
||||
bench_square,
|
||||
bench_invert,
|
||||
bench_sqrt,
|
||||
);
|
||||
criterion_main!(benches);
|
||||
|
|
|
@ -1,51 +1,58 @@
|
|||
#![feature(test)]
|
||||
|
||||
extern crate test;
|
||||
|
||||
use criterion::{criterion_group, criterion_main, Criterion};
|
||||
use jubjub::*;
|
||||
use test::Bencher;
|
||||
|
||||
#[bench]
|
||||
fn bench_mul_assign(bencher: &mut Bencher) {
|
||||
fn bench_add_assign(c: &mut Criterion) {
|
||||
let mut n = Fr::one();
|
||||
let b = -Fr::one();
|
||||
bencher.iter(move || {
|
||||
n *= &b;
|
||||
let neg_one = -Fr::one();
|
||||
c.bench_function("Fr add_assign", |b| {
|
||||
b.iter(move || {
|
||||
n += &neg_one;
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_sub_assign(bencher: &mut Bencher) {
|
||||
fn bench_sub_assign(c: &mut Criterion) {
|
||||
let mut n = Fr::one();
|
||||
let b = -Fr::one();
|
||||
bencher.iter(move || {
|
||||
n -= &b;
|
||||
let neg_one = -Fr::one();
|
||||
c.bench_function("Fr sub_assign", |b| {
|
||||
b.iter(move || {
|
||||
n -= &neg_one;
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_add_assign(bencher: &mut Bencher) {
|
||||
fn bench_mul_assign(c: &mut Criterion) {
|
||||
let mut n = Fr::one();
|
||||
let b = -Fr::one();
|
||||
bencher.iter(move || {
|
||||
n += &b;
|
||||
let neg_one = -Fr::one();
|
||||
c.bench_function("Fr mul_assign", |b| {
|
||||
b.iter(move || {
|
||||
n *= &neg_one;
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_square_assign(bencher: &mut Bencher) {
|
||||
fn bench_square(c: &mut Criterion) {
|
||||
let n = Fr::one();
|
||||
bencher.iter(move || n.square());
|
||||
c.bench_function("Fr square", |b| b.iter(move || n.square()));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_invert(bencher: &mut Bencher) {
|
||||
fn bench_invert(c: &mut Criterion) {
|
||||
let n = Fr::one();
|
||||
bencher.iter(move || n.invert());
|
||||
c.bench_function("Fr invert", |b| b.iter(move || n.invert()));
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_sqrt(bencher: &mut Bencher) {
|
||||
fn bench_sqrt(c: &mut Criterion) {
|
||||
let n = Fr::one().double().double();
|
||||
bencher.iter(move || n.sqrt());
|
||||
c.bench_function("Fr sqrt", |b| b.iter(move || n.sqrt()));
|
||||
}
|
||||
|
||||
criterion_group!(
|
||||
benches,
|
||||
bench_add_assign,
|
||||
bench_sub_assign,
|
||||
bench_mul_assign,
|
||||
bench_square,
|
||||
bench_invert,
|
||||
bench_sqrt,
|
||||
);
|
||||
criterion_main!(benches);
|
||||
|
|
|
@ -1,58 +1,73 @@
|
|||
#![feature(test)]
|
||||
|
||||
extern crate test;
|
||||
|
||||
use criterion::{criterion_group, criterion_main, Criterion};
|
||||
use jubjub::*;
|
||||
use test::Bencher;
|
||||
|
||||
// Non-Niels
|
||||
|
||||
#[bench]
|
||||
fn bench_point_doubling(bencher: &mut Bencher) {
|
||||
fn bench_point_doubling(c: &mut Criterion) {
|
||||
let a = ExtendedPoint::identity();
|
||||
bencher.iter(move || a.double());
|
||||
c.bench_function("Jubjub point doubling", |bencher| {
|
||||
bencher.iter(move || a.double())
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_point_addition(bencher: &mut Bencher) {
|
||||
fn bench_point_addition(c: &mut Criterion) {
|
||||
let a = ExtendedPoint::identity();
|
||||
let b = -ExtendedPoint::identity();
|
||||
bencher.iter(move || a + b);
|
||||
c.bench_function("Jubjub point addition", |bencher| {
|
||||
bencher.iter(move || a + b)
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_point_subtraction(bencher: &mut Bencher) {
|
||||
fn bench_point_subtraction(c: &mut Criterion) {
|
||||
let a = ExtendedPoint::identity();
|
||||
let b = -ExtendedPoint::identity();
|
||||
bencher.iter(move || a + b);
|
||||
c.bench_function("Jubjub point subtraction", |bencher| {
|
||||
bencher.iter(move || a + b)
|
||||
});
|
||||
}
|
||||
|
||||
// Niels
|
||||
|
||||
#[bench]
|
||||
fn bench_cached_point_addition(bencher: &mut Bencher) {
|
||||
fn bench_cached_point_addition(c: &mut Criterion) {
|
||||
let a = ExtendedPoint::identity();
|
||||
let b = ExtendedPoint::identity().to_niels();
|
||||
bencher.iter(move || &a + &b);
|
||||
c.bench_function("Jubjub cached point addition", |bencher| {
|
||||
bencher.iter(move || a + b)
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_cached_affine_point_subtraction(bencher: &mut Bencher) {
|
||||
let a = ExtendedPoint::identity();
|
||||
let b = AffinePoint::identity().to_niels();
|
||||
bencher.iter(move || &a + &b);
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_cached_point_subtraction(bencher: &mut Bencher) {
|
||||
fn bench_cached_point_subtraction(c: &mut Criterion) {
|
||||
let a = ExtendedPoint::identity();
|
||||
let b = ExtendedPoint::identity().to_niels();
|
||||
bencher.iter(move || &a + &b);
|
||||
c.bench_function("Jubjub cached point subtraction", |bencher| {
|
||||
bencher.iter(move || a + b)
|
||||
});
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn bench_cached_affine_point_addition(bencher: &mut Bencher) {
|
||||
fn bench_cached_affine_point_addition(c: &mut Criterion) {
|
||||
let a = ExtendedPoint::identity();
|
||||
let b = AffinePoint::identity().to_niels();
|
||||
bencher.iter(move || &a + &b);
|
||||
c.bench_function("Jubjub cached affine point addition", |bencher| {
|
||||
bencher.iter(move || a + b)
|
||||
});
|
||||
}
|
||||
|
||||
fn bench_cached_affine_point_subtraction(c: &mut Criterion) {
|
||||
let a = ExtendedPoint::identity();
|
||||
let b = AffinePoint::identity().to_niels();
|
||||
c.bench_function("Jubjub cached affine point subtraction", |bencher| {
|
||||
bencher.iter(move || a + b)
|
||||
});
|
||||
}
|
||||
|
||||
criterion_group!(
|
||||
benches,
|
||||
bench_point_doubling,
|
||||
bench_point_addition,
|
||||
bench_point_subtraction,
|
||||
bench_cached_point_addition,
|
||||
bench_cached_point_subtraction,
|
||||
bench_cached_affine_point_addition,
|
||||
bench_cached_affine_point_subtraction,
|
||||
);
|
||||
criterion_main!(benches);
|
||||
|
|
Loading…
Reference in New Issue