Migrate jubjub benchmarks to criterion
This commit is contained in:
parent
f44556d7bf
commit
7ea1da5d6f
|
@ -493,6 +493,7 @@ name = "jubjub"
|
||||||
version = "0.3.0"
|
version = "0.3.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bls12_381 0.1.0",
|
"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_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)",
|
"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)",
|
"subtle 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
|
|
@ -22,6 +22,9 @@ default-features = false
|
||||||
version = "^2.2.1"
|
version = "^2.2.1"
|
||||||
default-features = false
|
default-features = false
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
criterion = "0.3"
|
||||||
|
|
||||||
[dev-dependencies.rand_core]
|
[dev-dependencies.rand_core]
|
||||||
version = "0.5"
|
version = "0.5"
|
||||||
default-features = false
|
default-features = false
|
||||||
|
@ -32,3 +35,15 @@ default-features = false
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
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)]
|
use criterion::{criterion_group, criterion_main, Criterion};
|
||||||
|
|
||||||
extern crate test;
|
|
||||||
|
|
||||||
use jubjub::*;
|
use jubjub::*;
|
||||||
use test::Bencher;
|
|
||||||
|
|
||||||
#[bench]
|
fn bench_add_assign(c: &mut Criterion) {
|
||||||
fn bench_mul_assign(bencher: &mut Bencher) {
|
|
||||||
let mut n = Fq::one();
|
let mut n = Fq::one();
|
||||||
let b = -Fq::one();
|
let neg_one = -Fq::one();
|
||||||
bencher.iter(move || {
|
c.bench_function("Fq add_assign", |b| {
|
||||||
n *= &b;
|
b.iter(move || {
|
||||||
|
n += &neg_one;
|
||||||
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[bench]
|
fn bench_sub_assign(c: &mut Criterion) {
|
||||||
fn bench_sub_assign(bencher: &mut Bencher) {
|
|
||||||
let mut n = Fq::one();
|
let mut n = Fq::one();
|
||||||
let b = -Fq::one();
|
let neg_one = -Fq::one();
|
||||||
bencher.iter(move || {
|
c.bench_function("Fq sub_assign", |b| {
|
||||||
n -= &b;
|
b.iter(move || {
|
||||||
|
n -= &neg_one;
|
||||||
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[bench]
|
fn bench_mul_assign(c: &mut Criterion) {
|
||||||
fn bench_add_assign(bencher: &mut Bencher) {
|
|
||||||
let mut n = Fq::one();
|
let mut n = Fq::one();
|
||||||
let b = -Fq::one();
|
let neg_one = -Fq::one();
|
||||||
bencher.iter(move || {
|
c.bench_function("Fq mul_assign", |b| {
|
||||||
n += &b;
|
b.iter(move || {
|
||||||
|
n *= &neg_one;
|
||||||
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[bench]
|
fn bench_square(c: &mut Criterion) {
|
||||||
fn bench_square_assign(bencher: &mut Bencher) {
|
|
||||||
let n = Fq::one();
|
let n = Fq::one();
|
||||||
bencher.iter(move || n.square());
|
c.bench_function("Fq square", |b| b.iter(move || n.square()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[bench]
|
fn bench_invert(c: &mut Criterion) {
|
||||||
fn bench_invert(bencher: &mut Bencher) {
|
|
||||||
let n = Fq::one();
|
let n = Fq::one();
|
||||||
bencher.iter(move || n.invert());
|
c.bench_function("Fq invert", |b| b.iter(move || n.invert()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[bench]
|
fn bench_sqrt(c: &mut Criterion) {
|
||||||
fn bench_sqrt(bencher: &mut Bencher) {
|
|
||||||
let n = Fq::one().double().double();
|
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)]
|
use criterion::{criterion_group, criterion_main, Criterion};
|
||||||
|
|
||||||
extern crate test;
|
|
||||||
|
|
||||||
use jubjub::*;
|
use jubjub::*;
|
||||||
use test::Bencher;
|
|
||||||
|
|
||||||
#[bench]
|
fn bench_add_assign(c: &mut Criterion) {
|
||||||
fn bench_mul_assign(bencher: &mut Bencher) {
|
|
||||||
let mut n = Fr::one();
|
let mut n = Fr::one();
|
||||||
let b = -Fr::one();
|
let neg_one = -Fr::one();
|
||||||
bencher.iter(move || {
|
c.bench_function("Fr add_assign", |b| {
|
||||||
n *= &b;
|
b.iter(move || {
|
||||||
|
n += &neg_one;
|
||||||
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[bench]
|
fn bench_sub_assign(c: &mut Criterion) {
|
||||||
fn bench_sub_assign(bencher: &mut Bencher) {
|
|
||||||
let mut n = Fr::one();
|
let mut n = Fr::one();
|
||||||
let b = -Fr::one();
|
let neg_one = -Fr::one();
|
||||||
bencher.iter(move || {
|
c.bench_function("Fr sub_assign", |b| {
|
||||||
n -= &b;
|
b.iter(move || {
|
||||||
|
n -= &neg_one;
|
||||||
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[bench]
|
fn bench_mul_assign(c: &mut Criterion) {
|
||||||
fn bench_add_assign(bencher: &mut Bencher) {
|
|
||||||
let mut n = Fr::one();
|
let mut n = Fr::one();
|
||||||
let b = -Fr::one();
|
let neg_one = -Fr::one();
|
||||||
bencher.iter(move || {
|
c.bench_function("Fr mul_assign", |b| {
|
||||||
n += &b;
|
b.iter(move || {
|
||||||
|
n *= &neg_one;
|
||||||
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[bench]
|
fn bench_square(c: &mut Criterion) {
|
||||||
fn bench_square_assign(bencher: &mut Bencher) {
|
|
||||||
let n = Fr::one();
|
let n = Fr::one();
|
||||||
bencher.iter(move || n.square());
|
c.bench_function("Fr square", |b| b.iter(move || n.square()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[bench]
|
fn bench_invert(c: &mut Criterion) {
|
||||||
fn bench_invert(bencher: &mut Bencher) {
|
|
||||||
let n = Fr::one();
|
let n = Fr::one();
|
||||||
bencher.iter(move || n.invert());
|
c.bench_function("Fr invert", |b| b.iter(move || n.invert()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[bench]
|
fn bench_sqrt(c: &mut Criterion) {
|
||||||
fn bench_sqrt(bencher: &mut Bencher) {
|
|
||||||
let n = Fr::one().double().double();
|
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)]
|
use criterion::{criterion_group, criterion_main, Criterion};
|
||||||
|
|
||||||
extern crate test;
|
|
||||||
|
|
||||||
use jubjub::*;
|
use jubjub::*;
|
||||||
use test::Bencher;
|
|
||||||
|
|
||||||
// Non-Niels
|
// Non-Niels
|
||||||
|
|
||||||
#[bench]
|
fn bench_point_doubling(c: &mut Criterion) {
|
||||||
fn bench_point_doubling(bencher: &mut Bencher) {
|
|
||||||
let a = ExtendedPoint::identity();
|
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(c: &mut Criterion) {
|
||||||
fn bench_point_addition(bencher: &mut Bencher) {
|
|
||||||
let a = ExtendedPoint::identity();
|
let a = ExtendedPoint::identity();
|
||||||
let b = -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(c: &mut Criterion) {
|
||||||
fn bench_point_subtraction(bencher: &mut Bencher) {
|
|
||||||
let a = ExtendedPoint::identity();
|
let a = ExtendedPoint::identity();
|
||||||
let b = -ExtendedPoint::identity();
|
let b = -ExtendedPoint::identity();
|
||||||
bencher.iter(move || a + b);
|
c.bench_function("Jubjub point subtraction", |bencher| {
|
||||||
|
bencher.iter(move || a + b)
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Niels
|
// Niels
|
||||||
|
|
||||||
#[bench]
|
fn bench_cached_point_addition(c: &mut Criterion) {
|
||||||
fn bench_cached_point_addition(bencher: &mut Bencher) {
|
|
||||||
let a = ExtendedPoint::identity();
|
let a = ExtendedPoint::identity();
|
||||||
let b = ExtendedPoint::identity().to_niels();
|
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_point_subtraction(c: &mut Criterion) {
|
||||||
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) {
|
|
||||||
let a = ExtendedPoint::identity();
|
let a = ExtendedPoint::identity();
|
||||||
let b = ExtendedPoint::identity().to_niels();
|
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(c: &mut Criterion) {
|
||||||
fn bench_cached_affine_point_addition(bencher: &mut Bencher) {
|
|
||||||
let a = ExtendedPoint::identity();
|
let a = ExtendedPoint::identity();
|
||||||
let b = AffinePoint::identity().to_niels();
|
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