@@ -2,6 +2,7 @@ use criterion::{criterion_group, criterion_main, Criterion};
22use leios_crypto_benchmarks:: cert:: * ;
33use leios_crypto_benchmarks:: registry:: { arbitrary_pools, PersistentId , Registry } ;
44use quickcheck:: { Arbitrary , Gen } ;
5+ use std:: env;
56
67use leios_crypto_benchmarks:: key:: { check_pop, key_gen, SecKey } ;
78use leios_crypto_benchmarks:: primitive:: {
@@ -101,14 +102,22 @@ fn benchmark_verify_vote_nonpersistent(c: &mut Criterion) {
101102 } ) ;
102103}
103104
104- fn benchmark_gen_cert ( c : & mut Criterion ) {
105+ fn benchmark_gen_cert_impl ( c : & mut Criterion , name : & ' static str , n_pools : usize , n_voters : usize ) {
105106 let g = & mut Gen :: new ( 10 ) ;
106- c. bench_function ( "cert::gen_cert" , |b| {
107+ c. bench_function ( name , |b| {
107108 b. iter_batched (
108109 || {
109110 let total = realistic_total_stake ( g) ;
110- let n = realistic_pool_count ( g) ;
111- let voters = realistic_voters ( g, n) ;
111+ let n = if n_pools > 0 {
112+ n_pools
113+ } else {
114+ realistic_pool_count ( g)
115+ } ;
116+ let voters = if n_voters > 0 {
117+ n_voters
118+ } else {
119+ realistic_voters ( g, n)
120+ } ;
112121 let stake = arbitrary_stake_distribution ( g, total, n, 11. , 1. ) ;
113122 let pools = arbitrary_pools ( g, & stake) ;
114123 let reg = Registry :: make ( & pools, voters) ;
@@ -121,14 +130,69 @@ fn benchmark_gen_cert(c: &mut Criterion) {
121130 } ) ;
122131}
123132
124- fn benchmark_verify_cert ( c : & mut Criterion ) {
133+ fn benchmark_gen_cert ( c : & mut Criterion ) {
134+ benchmark_gen_cert_impl ( c, "cert::gen_cert" , 0 , 0 ) ;
135+ if env:: var ( "BENCHMARK_CERT_EXTRA" ) . map ( |x| x == "1" ) == Result :: Ok ( true ) {
136+ benchmark_gen_cert_impl (
137+ c,
138+ "cert::gen_cert, n_pools = 2500, n_voters = 500" ,
139+ 2500 ,
140+ 500 ,
141+ ) ;
142+ benchmark_gen_cert_impl (
143+ c,
144+ "cert::gen_cert, n_pools = 2500, n_voters = 600" ,
145+ 2500 ,
146+ 600 ,
147+ ) ;
148+ benchmark_gen_cert_impl (
149+ c,
150+ "cert::gen_cert, n_pools = 2500, n_voters = 700" ,
151+ 2500 ,
152+ 700 ,
153+ ) ;
154+ benchmark_gen_cert_impl (
155+ c,
156+ "cert::gen_cert, n_pools = 2500, n_voters = 800" ,
157+ 2500 ,
158+ 800 ,
159+ ) ;
160+ benchmark_gen_cert_impl (
161+ c,
162+ "cert::gen_cert, n_pools = 2500, n_voters = 900" ,
163+ 2500 ,
164+ 900 ,
165+ ) ;
166+ benchmark_gen_cert_impl (
167+ c,
168+ "cert::gen_cert, n_pools = 2500, n_voters = 1000" ,
169+ 2500 ,
170+ 1000 ,
171+ ) ;
172+ }
173+ }
174+
175+ fn benchmark_verify_cert_impl (
176+ c : & mut Criterion ,
177+ name : & ' static str ,
178+ n_pools : usize ,
179+ n_voters : usize ,
180+ ) {
125181 let g = & mut Gen :: new ( 10 ) ;
126- c. bench_function ( "cert::verify_cert" , |b| {
182+ c. bench_function ( name , |b| {
127183 b. iter_batched (
128184 || {
129185 let total = realistic_total_stake ( g) ;
130- let n = realistic_pool_count ( g) ;
131- let voters = realistic_voters ( g, n) ;
186+ let n = if n_pools > 0 {
187+ n_pools
188+ } else {
189+ realistic_pool_count ( g)
190+ } ;
191+ let voters = if n_voters > 0 {
192+ n_voters
193+ } else {
194+ realistic_voters ( g, n)
195+ } ;
132196 let stake = arbitrary_stake_distribution ( g, total, n, 11. , 1. ) ;
133197 let pools = arbitrary_pools ( g, & stake) ;
134198 let reg = Registry :: make ( & pools, voters) ;
@@ -142,14 +206,69 @@ fn benchmark_verify_cert(c: &mut Criterion) {
142206 } ) ;
143207}
144208
145- fn benchmark_weigh_cert ( c : & mut Criterion ) {
209+ fn benchmark_verify_cert ( c : & mut Criterion ) {
210+ benchmark_verify_cert_impl ( c, "cert::verify_cert" , 0 , 0 ) ;
211+ if env:: var ( "BENCHMARK_CERT_EXTRA" ) . map ( |x| x == "1" ) == Result :: Ok ( true ) {
212+ benchmark_verify_cert_impl (
213+ c,
214+ "cert::verify_cert, n_pools = 2500, n_voters = 500" ,
215+ 2500 ,
216+ 500 ,
217+ ) ;
218+ benchmark_verify_cert_impl (
219+ c,
220+ "cert::verify_cert, n_pools = 2500, n_voters = 600" ,
221+ 2500 ,
222+ 600 ,
223+ ) ;
224+ benchmark_verify_cert_impl (
225+ c,
226+ "cert::verify_cert, n_pools = 2500, n_voters = 700" ,
227+ 2500 ,
228+ 700 ,
229+ ) ;
230+ benchmark_verify_cert_impl (
231+ c,
232+ "cert::verify_cert, n_pools = 2500, n_voters = 800" ,
233+ 2500 ,
234+ 800 ,
235+ ) ;
236+ benchmark_verify_cert_impl (
237+ c,
238+ "cert::verify_cert, n_pools = 2500, n_voters = 900" ,
239+ 2500 ,
240+ 900 ,
241+ ) ;
242+ benchmark_verify_cert_impl (
243+ c,
244+ "cert::verify_cert, n_pools = 2500, n_voters = 1000" ,
245+ 2500 ,
246+ 1000 ,
247+ ) ;
248+ }
249+ }
250+
251+ fn benchmark_weigh_cert_impl (
252+ c : & mut Criterion ,
253+ name : & ' static str ,
254+ n_pools : usize ,
255+ n_voters : usize ,
256+ ) {
146257 let g = & mut Gen :: new ( 10 ) ;
147- c. bench_function ( "cert::weigh_cert" , |b| {
258+ c. bench_function ( name , |b| {
148259 b. iter_batched (
149260 || {
150261 let total = realistic_total_stake ( g) ;
151- let n = realistic_pool_count ( g) ;
152- let voters = realistic_voters ( g, n) ;
262+ let n = if n_pools > 0 {
263+ n_pools
264+ } else {
265+ realistic_pool_count ( g)
266+ } ;
267+ let voters = if n_voters > 0 {
268+ n_voters
269+ } else {
270+ realistic_voters ( g, n)
271+ } ;
153272 let stake = arbitrary_stake_distribution ( g, total, n, 11. , 1. ) ;
154273 let pools = arbitrary_pools ( g, & stake) ;
155274 let reg = Registry :: make ( & pools, voters) ;
@@ -162,6 +281,47 @@ fn benchmark_weigh_cert(c: &mut Criterion) {
162281 )
163282 } ) ;
164283}
284+ fn benchmark_weigh_cert ( c : & mut Criterion ) {
285+ benchmark_weigh_cert_impl ( c, "cert::weigh_cert" , 0 , 0 ) ;
286+ if env:: var ( "BENCHMARK_CERT_EXTRA" ) . map ( |x| x == "1" ) == Result :: Ok ( true ) {
287+ benchmark_weigh_cert_impl (
288+ c,
289+ "cert::weigh_cert, n_pools = 2500, n_voters = 500" ,
290+ 2500 ,
291+ 500 ,
292+ ) ;
293+ benchmark_weigh_cert_impl (
294+ c,
295+ "cert::weigh_cert, n_pools = 2500, n_voters = 600" ,
296+ 2500 ,
297+ 600 ,
298+ ) ;
299+ benchmark_weigh_cert_impl (
300+ c,
301+ "cert::weigh_cert, n_pools = 2500, n_voters = 700" ,
302+ 2500 ,
303+ 700 ,
304+ ) ;
305+ benchmark_weigh_cert_impl (
306+ c,
307+ "cert::weigh_cert, n_pools = 2500, n_voters = 800" ,
308+ 2500 ,
309+ 800 ,
310+ ) ;
311+ benchmark_weigh_cert_impl (
312+ c,
313+ "cert::weigh_cert, n_pools = 2500, n_voters = 900" ,
314+ 2500 ,
315+ 900 ,
316+ ) ;
317+ benchmark_weigh_cert_impl (
318+ c,
319+ "cert::weigh_cert, n_pools = 2500, n_voters = 1000" ,
320+ 2500 ,
321+ 1000 ,
322+ ) ;
323+ }
324+ }
165325
166326criterion_group ! (
167327 benches,
0 commit comments