Skip to content

Commit 16cc651

Browse files
committed
Benchmark works on ranges of n now
1 parent 6549ab4 commit 16cc651

1 file changed

Lines changed: 83 additions & 79 deletions

File tree

benches/perf.rs

Lines changed: 83 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -24,85 +24,89 @@ fn apply_permutation_group(vec_a: Vec<G1Affine>, permutation: &Vec<u32>) -> Vec<
2424
}
2525

2626
fn benchmark_shuffle(c: &mut Criterion) {
27-
let mut rng = StdRng::seed_from_u64(0u64);
28-
29-
let N = 512;
30-
let N_BLINDERS = 4;
31-
let ell = N - N_BLINDERS;
32-
33-
// Construct the CRS
34-
let crs = generate_crs(ell);
35-
36-
// Get witnesses: the permutation, the randomizer, and a bunch of blinders
37-
let mut permutation: Vec<u32> = (0..ell as u32).collect();
38-
permutation.shuffle(&mut rng);
39-
let k = Fr::rand(&mut rng);
40-
let vec_r_m = generate_blinders(&mut rng, N_BLINDERS);
41-
42-
// Get shuffle inputs
43-
let vec_R: Vec<G1Affine> = iter::repeat_with(|| G1Projective::rand(&mut rng).into_affine())
44-
.take(ell)
45-
.collect();
46-
let vec_S: Vec<G1Affine> = iter::repeat_with(|| G1Projective::rand(&mut rng).into_affine())
47-
.take(ell)
48-
.collect();
49-
50-
// Derive shuffled outputs
51-
c.bench_function("shuffling", |b| {
52-
b.iter(|| {
53-
let mut vec_T: Vec<G1Affine> = vec_R.iter().map(|R| R.mul(k).into_affine()).collect();
54-
let mut vec_U: Vec<G1Affine> = vec_S.iter().map(|S| S.mul(k).into_affine()).collect();
55-
vec_T = apply_permutation_group(vec_T, &permutation);
56-
vec_U = apply_permutation_group(vec_U, &permutation);
57-
})
58-
});
59-
60-
let mut vec_T: Vec<G1Affine> = vec_R.iter().map(|R| R.mul(k).into_affine()).collect();
61-
let mut vec_U: Vec<G1Affine> = vec_S.iter().map(|S| S.mul(k).into_affine()).collect();
62-
vec_T = apply_permutation_group(vec_T, &permutation);
63-
vec_U = apply_permutation_group(vec_U, &permutation);
64-
65-
let range_as_fr: Vec<Fr> = (0..ell as u32).into_iter().map(|s| Fr::from(s)).collect();
66-
let sigma_ell = get_permutation(&range_as_fr, &permutation);
67-
let M = msm(&crs.vec_G, &sigma_ell) + msm(&crs.vec_H, &vec_r_m);
68-
69-
c.bench_function("prover", |b| {
70-
b.iter(|| {
71-
CurdleproofsProof::new(
72-
&crs,
73-
vec_R.clone(),
74-
vec_S.clone(),
75-
vec_T.clone(),
76-
vec_U.clone(),
77-
M,
78-
permutation.clone(),
79-
k,
80-
vec_r_m.clone(),
81-
&mut rng,
82-
);
83-
})
84-
});
85-
86-
let shuffle_proof = CurdleproofsProof::new(
87-
&crs,
88-
vec_R.clone(),
89-
vec_S.clone(),
90-
vec_T.clone(),
91-
vec_U.clone(),
92-
M,
93-
permutation,
94-
k,
95-
vec_r_m,
96-
&mut rng,
97-
);
98-
99-
c.bench_function("verifier", |b| {
100-
b.iter(|| {
101-
assert!(shuffle_proof
102-
.verify(&crs, &vec_R, &vec_S, &vec_T, &vec_U, &M, &mut rng)
103-
.is_ok());
104-
})
105-
});
27+
let mut group = c.benchmark_group("benchmark_shuffle");
28+
for n in 8usize..=256 {
29+
let mut rng = StdRng::seed_from_u64(0u64);
30+
31+
let N = n;
32+
let N_BLINDERS = 4;
33+
let ell = N - N_BLINDERS;
34+
35+
// Construct the CRS
36+
let crs = generate_crs(ell);
37+
38+
// Get witnesses: the permutation, the randomizer, and a bunch of blinders
39+
let mut permutation: Vec<u32> = (0..ell as u32).collect();
40+
permutation.shuffle(&mut rng);
41+
let k = Fr::rand(&mut rng);
42+
let vec_r_m = generate_blinders(&mut rng, N_BLINDERS);
43+
44+
// Get shuffle inputs
45+
let vec_R: Vec<G1Affine> = iter::repeat_with(|| G1Projective::rand(&mut rng).into_affine())
46+
.take(ell)
47+
.collect();
48+
let vec_S: Vec<G1Affine> = iter::repeat_with(|| G1Projective::rand(&mut rng).into_affine())
49+
.take(ell)
50+
.collect();
51+
52+
// Derive shuffled outputs
53+
group.bench_with_input(BenchmarkId::new("shuffling",n), &n, |b, _| {
54+
b.iter(|| {
55+
let mut vec_T: Vec<G1Affine> = vec_R.iter().map(|R| R.mul(k).into_affine()).collect();
56+
let mut vec_U: Vec<G1Affine> = vec_S.iter().map(|S| S.mul(k).into_affine()).collect();
57+
vec_T = apply_permutation_group(vec_T, &permutation);
58+
vec_U = apply_permutation_group(vec_U, &permutation);
59+
})
60+
});
61+
62+
let mut vec_T: Vec<G1Affine> = vec_R.iter().map(|R| R.mul(k).into_affine()).collect();
63+
let mut vec_U: Vec<G1Affine> = vec_S.iter().map(|S| S.mul(k).into_affine()).collect();
64+
vec_T = apply_permutation_group(vec_T, &permutation);
65+
vec_U = apply_permutation_group(vec_U, &permutation);
66+
67+
let range_as_fr: Vec<Fr> = (0..ell as u32).into_iter().map(|s| Fr::from(s)).collect();
68+
let sigma_ell = get_permutation(&range_as_fr, &permutation);
69+
let M = msm(&crs.vec_G, &sigma_ell) + msm(&crs.vec_H, &vec_r_m);
70+
71+
group.bench_with_input(BenchmarkId::new("prover",n),&n, |b, _| {
72+
b.iter(|| {
73+
CurdleproofsProof::new(
74+
&crs,
75+
vec_R.clone(),
76+
vec_S.clone(),
77+
vec_T.clone(),
78+
vec_U.clone(),
79+
M,
80+
permutation.clone(),
81+
k,
82+
vec_r_m.clone(),
83+
&mut rng,
84+
);
85+
})
86+
});
87+
88+
let shuffle_proof = CurdleproofsProof::new(
89+
&crs,
90+
vec_R.clone(),
91+
vec_S.clone(),
92+
vec_T.clone(),
93+
vec_U.clone(),
94+
M,
95+
permutation,
96+
k,
97+
vec_r_m,
98+
&mut rng,
99+
);
100+
101+
group.bench_with_input(BenchmarkId::new("verifier",n), &n, |b, _| {
102+
b.iter(|| {
103+
assert!(shuffle_proof
104+
.verify(&crs, &vec_R, &vec_S, &vec_T, &vec_U, &M, &mut rng)
105+
.is_ok());
106+
})
107+
});
108+
}
109+
group.finish();
106110
}
107111

108112
criterion_group! {name = shuffle;

0 commit comments

Comments
 (0)