-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Field arithmetic benchmark + reworked assembly (+40% perf) (#49)
* add benchmarks for BN256 * small assembly changes: adcx -> adc * rework mul assembly to use 2 carry chains * remove need for nightly for asm by using register instead of constant * remove unused regs * run cargo fmt
- Loading branch information
Showing
3 changed files
with
287 additions
and
567 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,3 +56,7 @@ codegen-units = 1 | |
[[bench]] | ||
name = "less_than" | ||
harness = false | ||
|
||
[[bench]] | ||
name = "bn256_field" | ||
harness = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
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); |
Oops, something went wrong.