Skip to content

Commit 30a48ab

Browse files
authored
elliptic-curve: add mul_by_generator(_vartime) benchmarks (#2389)
These are helpful for seeing the speedups when we add basepoint tables
1 parent f7e7c3d commit 30a48ab

1 file changed

Lines changed: 20 additions & 5 deletions

File tree

elliptic-curve/src/dev.rs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub use mock_curve::*;
1414
/// Write a series of `criterion`-based benchmarks for arithmetic on a projective curve point.
1515
#[macro_export]
1616
macro_rules! bench_projective {
17-
($name:ident, $desc:expr, $point_a:expr, $point_b:expr, $scalar:expr) => {
17+
($name:ident, $point_type:ty, $point_a:expr, $point_b:expr, $scalar:expr) => {
1818
fn bench_add<M: ::criterion::measurement::Measurement>(
1919
group: &mut ::criterion::BenchmarkGroup<'_, M>,
2020
) {
@@ -38,20 +38,35 @@ macro_rules! bench_projective {
3838
group.bench_function("neg", |b| b.iter(|| -x));
3939
}
4040

41-
fn bench_scalar_mul<M: ::criterion::measurement::Measurement>(
41+
fn bench_point_mul<M: ::criterion::measurement::Measurement>(
4242
group: &mut ::criterion::BenchmarkGroup<'_, M>,
4343
) {
4444
let p = core::hint::black_box($point_a);
4545
let s = core::hint::black_box($scalar);
46-
group.bench_function("scalar mul", |b| b.iter(|| p * s));
46+
group.bench_function("point-scalar mul", |b| b.iter(|| p * s));
47+
}
48+
49+
fn bench_point_mul_by_generator<M: ::criterion::measurement::Measurement>(
50+
group: &mut ::criterion::BenchmarkGroup<'_, M>,
51+
) {
52+
use $crate::{group::Group, ops::MulByGeneratorVartime};
53+
54+
let s = core::hint::black_box($scalar);
55+
group.bench_function("generator-scalar mul", |b| {
56+
b.iter(|| ProjectivePoint::mul_by_generator(&s))
57+
});
58+
group.bench_function("generator-scalar mul (variable-time)", |b| {
59+
b.iter(|| ProjectivePoint::mul_by_generator_vartime(&s))
60+
});
4761
}
4862

4963
pub fn $name(c: &mut ::criterion::Criterion) {
50-
let mut group = c.benchmark_group($desc);
64+
let mut group = c.benchmark_group(stringify!($point_type));
5165
bench_add(&mut group);
5266
bench_sub(&mut group);
5367
bench_neg(&mut group);
54-
bench_scalar_mul(&mut group);
68+
bench_point_mul(&mut group);
69+
bench_point_mul_by_generator(&mut group);
5570
group.finish();
5671
}
5772
};

0 commit comments

Comments
 (0)