forked from privacy-scaling-explorations/halo2curves
-
Notifications
You must be signed in to change notification settings - Fork 10
/
bn256_field.rs
51 lines (44 loc) · 1.75 KB
/
bn256_field.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use criterion::{black_box, criterion_group, criterion_main, Criterion, Throughput};
use halo2curves::{bn256::*, ff::Field, ff_ext::Legendre};
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())
});
group.bench_function("bn256_fq_invert", |bencher| {
bencher.iter(|| black_box(&a).invert())
});
group.bench_function("bn256_fq_legendre", |bencher| {
bencher.iter(|| black_box(&a).legendre())
});
}
criterion_group!(benches, bench_bn256_field);
criterion_main!(benches);