Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Field arithmetic benchmark + reworked assembly (+40% perf) #49

Merged
merged 6 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,7 @@ codegen-units = 1
[[bench]]
name = "less_than"
harness = false

[[bench]]
name = "bn256_field"
harness = false
34 changes: 34 additions & 0 deletions benches/bn256_field.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion, Throughput};
use halo2curves::bn256::*;
use halo2curves::ff::Field;
use rand::SeedableRng;
use rand_xorshift::XorShiftRng;

pub fn bench_bn256_field(c: &mut Criterion) {
let mut rng = XorShiftRng::from_seed([
0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06, 0xbc,
0xe5,
]);

let a = Fq::random(&mut rng);
let b = Fq::random(&mut rng);

#[cfg(not(feature = "asm"))]
let mut group = c.benchmark_group("BN256 Field Arithmetic (no assembly)");

#[cfg(feature = "asm")]
let mut group = c.benchmark_group("BN256 Field Arithmetic (with assembly)");

group.significance_level(0.1).sample_size(10000);
group.throughput(Throughput::Elements(1));

group.bench_function("bn256_fq_add", |bencher| bencher.iter(|| black_box(&a).add(black_box(&b))));
group.bench_function("bn256_fq_double", |bencher| bencher.iter(|| black_box(&a).double()));
group.bench_function("bn256_fq_sub", |bencher| bencher.iter(|| black_box(&a).sub(black_box(&b))));
group.bench_function("bn256_fq_neg", |bencher| bencher.iter(|| black_box(&a).neg()));
group.bench_function("bn256_fq_mul", |bencher| bencher.iter(|| black_box(&a).mul(black_box(&b))));
group.bench_function("bn256_fq_square", |bencher| bencher.iter(|| black_box(&a).square()));
}

criterion_group!(benches, bench_bn256_field);
criterion_main!(benches);
Loading