Skip to content

Commit

Permalink
Add basic group operation benchmarks (#26)
Browse files Browse the repository at this point in the history
* Add basic group op benchmarks

* Replace generator with random point in the curve

* nits
  • Loading branch information
davidnevadoc authored Aug 7, 2023
1 parent d3c6a74 commit 526c07c
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,8 @@ harness = false
[[bench]]
name = "bn256_field"
harness = false
required-features = ["reexport"]
required-features = ["reexport"]

[[bench]]
name = "group"
harness = false
52 changes: 52 additions & 0 deletions benches/group.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use ff::Field;
use group::prime::PrimeCurveAffine;
use halo2curves::secp256k1::Secp256k1;
use pasta_curves::arithmetic::CurveExt;
use rand_core::OsRng;

fn criterion_benchmark<G: CurveExt>(c: &mut Criterion) {
// G1Projective
{
let name = "GProjective";
let p1 = G::random(OsRng);
let p2 = G::random(OsRng);
let p1_affine = G::AffineExt::from(p1);
let s = G::ScalarExt::random(OsRng);

const N: usize = 1000;
let v = vec![G::generator(); N];
let mut q = vec![G::AffineExt::identity(); N];

c.bench_function(&format!("{} check on curve", name), move |b| {
b.iter(|| black_box(p1).is_on_curve())
});
c.bench_function(&format!("{} check equality", name), move |b| {
b.iter(|| black_box(p1) == black_box(p1))
});
c.bench_function(&format!("{} to affine", name), move |b| {
b.iter(|| G::AffineExt::from(black_box(p1)))
});
c.bench_function(&format!("{} doubling", name), move |b| {
b.iter(|| black_box(p1).double())
});
c.bench_function(&format!("{} addition", name), move |b| {
b.iter(|| black_box(p1).add(&p2))
});
c.bench_function(&format!("{} mixed addition", name), move |b| {
b.iter(|| black_box(p2).add(&p1_affine))
});
c.bench_function(&format!("{} scalar multiplication", name), move |b| {
b.iter(|| black_box(p1) * black_box(s))
});
c.bench_function(&format!("{} batch to affine n={}", name, N), move |b| {
b.iter(|| {
G::batch_normalize(black_box(&v), black_box(&mut q));
black_box(&q)[0]
})
});
}
}

criterion_group!(benches, criterion_benchmark<Secp256k1>);
criterion_main!(benches);

0 comments on commit 526c07c

Please sign in to comment.