2019-12-19 13:55:01 -08:00
|
|
|
use criterion::{criterion_group, criterion_main, Criterion};
|
2019-12-12 10:32:47 -08:00
|
|
|
use jubjub::*;
|
|
|
|
|
|
|
|
// Non-Niels
|
|
|
|
|
2019-12-19 13:55:01 -08:00
|
|
|
fn bench_point_doubling(c: &mut Criterion) {
|
2019-12-12 10:32:47 -08:00
|
|
|
let a = ExtendedPoint::identity();
|
2019-12-19 13:55:01 -08:00
|
|
|
c.bench_function("Jubjub point doubling", |bencher| {
|
|
|
|
bencher.iter(move || a.double())
|
|
|
|
});
|
2019-12-12 10:32:47 -08:00
|
|
|
}
|
|
|
|
|
2019-12-19 13:55:01 -08:00
|
|
|
fn bench_point_addition(c: &mut Criterion) {
|
2019-12-12 10:32:47 -08:00
|
|
|
let a = ExtendedPoint::identity();
|
|
|
|
let b = -ExtendedPoint::identity();
|
2019-12-19 13:55:01 -08:00
|
|
|
c.bench_function("Jubjub point addition", |bencher| {
|
|
|
|
bencher.iter(move || a + b)
|
|
|
|
});
|
2019-12-12 10:32:47 -08:00
|
|
|
}
|
|
|
|
|
2019-12-19 13:55:01 -08:00
|
|
|
fn bench_point_subtraction(c: &mut Criterion) {
|
2019-12-12 10:32:47 -08:00
|
|
|
let a = ExtendedPoint::identity();
|
|
|
|
let b = -ExtendedPoint::identity();
|
2019-12-19 13:55:01 -08:00
|
|
|
c.bench_function("Jubjub point subtraction", |bencher| {
|
|
|
|
bencher.iter(move || a + b)
|
|
|
|
});
|
2019-12-12 10:32:47 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Niels
|
|
|
|
|
2019-12-19 13:55:01 -08:00
|
|
|
fn bench_cached_point_addition(c: &mut Criterion) {
|
2019-12-12 10:32:47 -08:00
|
|
|
let a = ExtendedPoint::identity();
|
|
|
|
let b = ExtendedPoint::identity().to_niels();
|
2019-12-19 13:55:01 -08:00
|
|
|
c.bench_function("Jubjub cached point addition", |bencher| {
|
|
|
|
bencher.iter(move || a + b)
|
|
|
|
});
|
2019-12-12 10:32:47 -08:00
|
|
|
}
|
|
|
|
|
2019-12-19 13:55:01 -08:00
|
|
|
fn bench_cached_point_subtraction(c: &mut Criterion) {
|
2019-12-12 10:32:47 -08:00
|
|
|
let a = ExtendedPoint::identity();
|
2019-12-19 13:55:01 -08:00
|
|
|
let b = ExtendedPoint::identity().to_niels();
|
|
|
|
c.bench_function("Jubjub cached point subtraction", |bencher| {
|
|
|
|
bencher.iter(move || a + b)
|
|
|
|
});
|
2019-12-12 10:32:47 -08:00
|
|
|
}
|
|
|
|
|
2019-12-19 13:55:01 -08:00
|
|
|
fn bench_cached_affine_point_addition(c: &mut Criterion) {
|
2019-12-12 10:32:47 -08:00
|
|
|
let a = ExtendedPoint::identity();
|
2019-12-19 13:55:01 -08:00
|
|
|
let b = AffinePoint::identity().to_niels();
|
|
|
|
c.bench_function("Jubjub cached affine point addition", |bencher| {
|
|
|
|
bencher.iter(move || a + b)
|
|
|
|
});
|
2019-12-12 10:32:47 -08:00
|
|
|
}
|
|
|
|
|
2019-12-19 13:55:01 -08:00
|
|
|
fn bench_cached_affine_point_subtraction(c: &mut Criterion) {
|
2019-12-12 10:32:47 -08:00
|
|
|
let a = ExtendedPoint::identity();
|
|
|
|
let b = AffinePoint::identity().to_niels();
|
2019-12-19 13:55:01 -08:00
|
|
|
c.bench_function("Jubjub cached affine point subtraction", |bencher| {
|
|
|
|
bencher.iter(move || a + b)
|
|
|
|
});
|
2019-12-12 10:32:47 -08:00
|
|
|
}
|
2019-12-19 13:55:01 -08:00
|
|
|
|
|
|
|
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);
|