forked from jackoelv/bellperson
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lc.rs
38 lines (34 loc) · 1.3 KB
/
lc.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
use bellperson::{bls::Bls12, Index, LinearCombination, Variable};
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use ff::{Field, ScalarEngine};
fn lc_benchmark(c: &mut Criterion) {
c.bench_function("LinearCombination::add((Fr, Variable))", |b| {
b.iter(|| {
let mut lc = LinearCombination::<Bls12>::zero();
for i in 0..100 {
let coeff = <Bls12 as ScalarEngine>::Fr::one();
lc = lc + (coeff, Variable::new_unchecked(Index::Aux(i)));
}
black_box(lc);
});
})
.bench_function("LinearCombination::add(LinearCombination)", |b| {
let mut lc1 = LinearCombination::<Bls12>::zero();
let mut lc2 = LinearCombination::<Bls12>::zero();
for i in 0..10 {
let coeff = <Bls12 as ScalarEngine>::Fr::one();
lc1 = lc1 + (coeff, Variable::new_unchecked(Index::Aux(i)));
let coeff = <Bls12 as ScalarEngine>::Fr::one();
lc2 = lc2 + (coeff, Variable::new_unchecked(Index::Aux(i * 2)));
}
b.iter(|| {
let mut lc = lc1.clone();
for _ in 0..10 {
lc = lc + &lc2;
}
black_box(lc);
});
});
}
criterion_group!(benches, lc_benchmark);
criterion_main!(benches);