Skip to content

Commit d4fa704

Browse files
authored
bp256: add ProjectivePoint benchmarks (#1588)
Uses the `elliptic_curve::bench_projective!` macro introduced in RustCrypto/traits#2177 to run a set of benchmarks against `ProjectivePoint`, including point addition, negation, and scalar multiplication. After this we can roll out all of the benchmark macros added to `bp256` to the curves which currently don't have any, and use the macros to replace some of the existing tests in the ones that do.
1 parent 76685c9 commit d4fa704

File tree

7 files changed

+46
-5
lines changed

7 files changed

+46
-5
lines changed

.github/workflows/bp256.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@ concurrency:
2626
cancel-in-progress: true
2727

2828
jobs:
29+
benches:
30+
runs-on: ubuntu-latest
31+
strategy:
32+
matrix:
33+
rust:
34+
- 1.85.0 # MSRV
35+
- stable
36+
steps:
37+
- uses: actions/checkout@v6
38+
- uses: dtolnay/rust-toolchain@master
39+
with:
40+
toolchain: ${{ matrix.rust }}
41+
- run: cargo build --all-features --benches
42+
2943
build:
3044
runs-on: ubuntu-latest
3145
strategy:

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bp256/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ sha2 = { version = "0.11.0-rc.3", optional = true, default-features = false }
2424

2525
[dev-dependencies]
2626
criterion = "0.7"
27+
elliptic-curve = { version = "0.14.0-rc.20", default-features = false, features = ["dev"] }
2728

2829
[features]
2930
default = ["pkcs8", "std"]
@@ -43,6 +44,11 @@ name = "field"
4344
harness = false
4445
required-features = ["arithmetic"]
4546

47+
[[bench]]
48+
name = "point"
49+
harness = false
50+
required-features = ["arithmetic"]
51+
4652
[[bench]]
4753
name = "scalar"
4854
harness = false

bp256/benches/field.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! bp256 `FieldElement` benchmarks
22
33
use bp256::BrainpoolP256r1;
4-
use criterion::{Criterion, criterion_group, criterion_main};
4+
use criterion::{criterion_group, criterion_main};
55
use primeorder::PrimeCurveParams;
66

77
type FieldElement = <BrainpoolP256r1 as PrimeCurveParams>::FieldElement;

bp256/benches/point.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//! bp256r1 `ProjectivePoint` benchmarks
2+
3+
use bp256::r1::{ProjectivePoint, Scalar};
4+
use criterion::{criterion_group, criterion_main};
5+
6+
const POINT_A: ProjectivePoint = ProjectivePoint::GENERATOR;
7+
const POINT_B: ProjectivePoint = ProjectivePoint::GENERATOR;
8+
9+
const SCALAR: Scalar =
10+
Scalar::from_hex_vartime("9bb0d8b72602b70dd5cfed99607a2e2c021dd0fe3b3af842df02c06f8c1a0f4e");
11+
12+
elliptic_curve::bench_projective!(
13+
bench_projective,
14+
"ProjectivePoint",
15+
POINT_A,
16+
POINT_B,
17+
SCALAR
18+
);
19+
20+
criterion_group!(benches, bench_projective);
21+
criterion_main!(benches);

bp256/benches/scalar.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! bp256 `Scalar` benchmarks
22
33
use bp256::Scalar;
4-
use criterion::{Criterion, criterion_group, criterion_main};
4+
use criterion::{criterion_group, criterion_main};
55

66
const SCALAR_A: Scalar =
77
Scalar::from_hex_vartime("9bb0d8b72602b70dd5cfed99607a2e2c021dd0fe3b3af842df02c06f8c1a0f4e");

primefield/src/dev.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ macro_rules! bench_field {
5555
group.bench_function("sqrt", |b| b.iter(|| x.sqrt()));
5656
}
5757

58-
fn $name(c: &mut Criterion) {
58+
fn $name(c: &mut ::criterion::Criterion) {
5959
let mut group = c.benchmark_group($desc);
6060
bench_add(&mut group);
6161
bench_sub(&mut group);

0 commit comments

Comments
 (0)