mirror of
https://github.com/saymrwulf/pasta_curves-source.git
synced 2026-09-04 20:03:39 +00:00
Add benchmarks for point operations.
Signed-off-by: Daira Hopwood <daira@jacaranda.org>
This commit is contained in:
parent
1bac885af5
commit
329f59493c
2 changed files with 48 additions and 0 deletions
|
|
@ -35,6 +35,10 @@ harness = false
|
||||||
name = "fq"
|
name = "fq"
|
||||||
harness = false
|
harness = false
|
||||||
|
|
||||||
|
[[bench]]
|
||||||
|
name = "point"
|
||||||
|
harness = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
subtle = "2.3"
|
subtle = "2.3"
|
||||||
ff = "0.10"
|
ff = "0.10"
|
||||||
|
|
|
||||||
44
benches/point.rs
Normal file
44
benches/point.rs
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
//! Benchmarks for point operations.
|
||||||
|
|
||||||
|
use criterion::{criterion_group, criterion_main, Criterion};
|
||||||
|
|
||||||
|
use pasta_curves::arithmetic::CurveExt;
|
||||||
|
use pasta_curves::{pallas, vesta};
|
||||||
|
|
||||||
|
fn criterion_benchmark(c: &mut Criterion) {
|
||||||
|
point_bench::<pallas::Point>(c, "Pallas");
|
||||||
|
point_bench::<vesta::Point>(c, "Vesta");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn point_bench<C: CurveExt>(c: &mut Criterion, name: &str) {
|
||||||
|
let mut group = c.benchmark_group(name);
|
||||||
|
|
||||||
|
let a = C::generator();
|
||||||
|
let b = a.double();
|
||||||
|
|
||||||
|
group.bench_function("point doubling", |bencher| bencher.iter(|| a.double()));
|
||||||
|
|
||||||
|
group.bench_function("point addition", |bencher| bencher.iter(|| a + b));
|
||||||
|
|
||||||
|
group.bench_function("point subtraction", |bencher| bencher.iter(|| a - b));
|
||||||
|
|
||||||
|
group.bench_function("point to_bytes", |bencher| bencher.iter(|| a.to_bytes()));
|
||||||
|
|
||||||
|
let repr = a.to_bytes();
|
||||||
|
group.bench_function("point from_bytes", |bencher| {
|
||||||
|
bencher.iter(|| C::from_bytes(&repr))
|
||||||
|
});
|
||||||
|
|
||||||
|
group.bench_function("point to_affine", |bencher| bencher.iter(|| a.to_affine()));
|
||||||
|
|
||||||
|
for &n in [100, 1000, 10000].iter() {
|
||||||
|
let input = vec![a; n];
|
||||||
|
let mut output = vec![C::AffineRepr::default(); n];
|
||||||
|
group.bench_function(format!("point batch_normalize/{}", n), |bencher| {
|
||||||
|
bencher.iter(|| C::batch_normalize(input.as_slice(), output.as_mut_slice()));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
criterion_group!(benches, criterion_benchmark);
|
||||||
|
criterion_main!(benches);
|
||||||
Loading…
Reference in a new issue