Skip to content

Commit 47bb5d7

Browse files
committed
Add benchmarks
1 parent f62cc79 commit 47bb5d7

File tree

1 file changed

+44
-2
lines changed

1 file changed

+44
-2
lines changed

ed448-goldilocks/benches/bench.rs

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use criterion::{BatchSize, Criterion, criterion_group, criterion_main};
22
use ed448_goldilocks::{
3-
Decaf448, DecafPoint, DecafScalar, Ed448, EdwardsPoint, EdwardsScalar, MontgomeryScalar,
4-
MontgomeryXpoint, ProjectiveMontgomeryXpoint,
3+
Curve448, Decaf448, DecafPoint, DecafScalar, Ed448, EdwardsPoint, EdwardsScalar,
4+
MontgomeryScalar, MontgomeryXpoint, ProjectiveMontgomeryPoint, ProjectiveMontgomeryXpoint,
55
};
66
use elliptic_curve::group::GroupEncoding;
77
use elliptic_curve::{Field, Group};
@@ -124,6 +124,48 @@ pub fn decaf448(c: &mut Criterion) {
124124
group.finish();
125125
}
126126

127+
pub fn curve448(c: &mut Criterion) {
128+
let mut group = c.benchmark_group("Curve448");
129+
130+
group.bench_function("scalar multiplication", |b| {
131+
b.iter_batched(
132+
|| {
133+
let point = ProjectiveMontgomeryPoint::try_from_rng(&mut OsRng).unwrap();
134+
let scalar = MontgomeryScalar::try_from_rng(&mut OsRng).unwrap();
135+
(point, scalar)
136+
},
137+
|(point, scalar)| point * scalar,
138+
BatchSize::SmallInput,
139+
)
140+
});
141+
142+
group.bench_function("point addition", |b| {
143+
b.iter_batched(
144+
|| {
145+
let p1 = ProjectiveMontgomeryPoint::try_from_rng(&mut OsRng).unwrap();
146+
let p2 = ProjectiveMontgomeryPoint::try_from_rng(&mut OsRng).unwrap();
147+
(p1, p2)
148+
},
149+
|(p1, p2)| p1 + p2,
150+
BatchSize::SmallInput,
151+
)
152+
});
153+
154+
group.bench_function("encode_to_curve", |b| {
155+
b.iter_batched(
156+
|| {
157+
let mut msg = [0; 64];
158+
OsRng.try_fill_bytes(&mut msg).unwrap();
159+
msg
160+
},
161+
|msg| Curve448::encode_from_bytes(&msg, b"test DST"),
162+
BatchSize::SmallInput,
163+
)
164+
});
165+
166+
group.finish();
167+
}
168+
127169
pub fn x448(c: &mut Criterion) {
128170
let mut group = c.benchmark_group("X448");
129171

0 commit comments

Comments
 (0)