Skip to content

Commit ab26405

Browse files
committed
Add a benchmark for linear combination
1 parent 6129117 commit ab26405

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

k256/bench/scalar.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use criterion::{
66
use hex_literal::hex;
77
use k256::{
88
elliptic_curve::{generic_array::arr, group::ff::PrimeField},
9-
ProjectivePoint, Scalar,
9+
lincomb, ProjectivePoint, Scalar,
1010
};
1111

1212
fn test_scalar_x() -> Scalar {
@@ -34,9 +34,18 @@ fn bench_point_mul<'a, M: Measurement>(group: &mut BenchmarkGroup<'a, M>) {
3434
group.bench_function("point-scalar mul", |b| b.iter(|| &p * &s));
3535
}
3636

37+
fn bench_point_lincomb<'a, M: Measurement>(group: &mut BenchmarkGroup<'a, M>) {
38+
let p = ProjectivePoint::generator();
39+
let m = hex!("AA5E28D6A97A2479A65527F7290311A3624D4CC0FA1578598EE3C2613BF99522");
40+
let s = Scalar::from_repr(m.into()).unwrap();
41+
group.bench_function("lincomb via mul+add", |b| b.iter(|| &p * &s + &p * &s));
42+
group.bench_function("lincomb", |b| b.iter(|| lincomb(&p, &p, &s, &s)));
43+
}
44+
3745
fn bench_high_level(c: &mut Criterion) {
3846
let mut group = c.benchmark_group("high-level operations");
3947
bench_point_mul(&mut group);
48+
bench_point_lincomb(&mut group);
4049
group.finish();
4150
}
4251

k256/src/arithmetic.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pub(crate) mod scalar;
88
mod util;
99

1010
pub use field::FieldElement;
11+
pub use mul::lincomb;
1112

1213
use affine::AffinePoint;
1314
use projective::ProjectivePoint;

k256/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub mod test_vectors;
6767
pub use elliptic_curve::{self, bigint::U256};
6868

6969
#[cfg(feature = "arithmetic")]
70-
pub use arithmetic::{affine::AffinePoint, projective::ProjectivePoint, scalar::Scalar};
70+
pub use arithmetic::{affine::AffinePoint, lincomb, projective::ProjectivePoint, scalar::Scalar};
7171

7272
#[cfg(feature = "expose-field")]
7373
pub use arithmetic::FieldElement;

0 commit comments

Comments
 (0)