@@ -21,11 +21,13 @@ const COMMIT_FREQUENCY: u32 = 10_000;
2121
2222cfg_if:: cfg_if! {
2323 if #[ cfg( not( full_bench) ) ] {
24- const ELEMENTS : [ u64 ; 1 ] = [ NUM_ELEMENTS ] ;
25- const OPERATIONS : [ u64 ; 1 ] = [ NUM_OPERATIONS ] ;
24+ const CASES : [ ( u64 , u64 ) ; 1 ] = [ ( NUM_ELEMENTS , NUM_OPERATIONS ) ] ;
2625 } else {
27- const ELEMENTS : [ u64 ; 2 ] = [ NUM_ELEMENTS , NUM_ELEMENTS * 10 ] ;
28- const OPERATIONS : [ u64 ; 2 ] = [ NUM_OPERATIONS , NUM_OPERATIONS * 10 ] ;
26+ const CASES : [ ( u64 , u64 ) ; 3 ] = [
27+ ( NUM_ELEMENTS , NUM_OPERATIONS ) ,
28+ ( NUM_ELEMENTS * 10 , NUM_OPERATIONS ) ,
29+ ( NUM_ELEMENTS * 3 , NUM_OPERATIONS * 3 ) ,
30+ ] ;
2931 }
3032}
3133
@@ -52,54 +54,52 @@ define_fixed_variants! {
5254
5355fn bench_fixed_value_init ( c : & mut Criterion ) {
5456 let cfg = Config :: default ( ) ;
55- for elements in ELEMENTS {
56- for operations in OPERATIONS {
57- for & variant in FIXED_VARIANTS {
58- let mut initialized = false ;
59- let runner = tokio:: Runner :: new ( cfg. clone ( ) ) ;
60- c. bench_function (
61- & format ! (
62- "{}/variant={} elements={elements} operations={operations}" ,
63- module_path!( ) ,
64- variant. name( ) ,
65- ) ,
66- |b| {
67- // Setup: populate database (once, on first sample).
68- if !initialized {
69- commonware_runtime:: tokio:: Runner :: new ( cfg. clone ( ) ) . start (
70- |ctx| async move {
71- dispatch_fixed ! ( ctx, variant, |db| {
72- populate_and_sync(
73- & mut db,
74- elements,
75- operations,
76- make_fixed_value,
77- )
78- . await ;
79- } ) ;
80- } ,
81- ) ;
82- initialized = true ;
83- }
57+ for ( elements, operations) in CASES {
58+ for & variant in FIXED_VARIANTS {
59+ let mut initialized = false ;
60+ let runner = tokio:: Runner :: new ( cfg. clone ( ) ) ;
61+ c. bench_function (
62+ & format ! (
63+ "{}/variant={} elements={elements} operations={operations}" ,
64+ module_path!( ) ,
65+ variant. name( ) ,
66+ ) ,
67+ |b| {
68+ // Setup: populate database (once, on first sample).
69+ if !initialized {
70+ commonware_runtime:: tokio:: Runner :: new ( cfg. clone ( ) ) . start (
71+ |ctx| async move {
72+ dispatch_fixed ! ( ctx, variant, |db| {
73+ populate_and_sync(
74+ & mut db,
75+ elements,
76+ operations,
77+ make_fixed_value,
78+ )
79+ . await ;
80+ } ) ;
81+ } ,
82+ ) ;
83+ initialized = true ;
84+ }
8485
85- // Benchmark: measure init time.
86- b. to_async ( & runner) . iter_custom ( |iters| async move {
87- let ctx = context:: get :: < Context > ( ) ;
88- dispatch_fixed_timed_init ! ( ctx, variant, iters, |db| {
89- assert_ne!( db. bounds( ) . await . end, 0 ) ;
90- } )
91- } ) ;
92- } ,
93- ) ;
86+ // Benchmark: measure init time.
87+ b. to_async ( & runner) . iter_custom ( |iters| async move {
88+ let ctx = context:: get :: < Context > ( ) ;
89+ dispatch_fixed_timed_init ! ( ctx, variant, iters, |db| {
90+ assert_ne!( db. bounds( ) . await . end, 0 ) ;
91+ } )
92+ } ) ;
93+ } ,
94+ ) ;
9495
95- // Cleanup: destroy database.
96- if initialized {
97- commonware_runtime:: tokio:: Runner :: new ( cfg. clone ( ) ) . start ( |ctx| async move {
98- dispatch_fixed ! ( ctx, variant, |db| {
99- db. destroy( ) . await . unwrap( ) ;
100- } ) ;
96+ // Cleanup: destroy database.
97+ if initialized {
98+ commonware_runtime:: tokio:: Runner :: new ( cfg. clone ( ) ) . start ( |ctx| async move {
99+ dispatch_fixed ! ( ctx, variant, |db| {
100+ db. destroy( ) . await . unwrap( ) ;
101101 } ) ;
102- }
102+ } ) ;
103103 }
104104 }
105105 }
@@ -116,54 +116,52 @@ define_vec_variants! {
116116
117117fn bench_var_value_init ( c : & mut Criterion ) {
118118 let cfg = Config :: default ( ) ;
119- for elements in ELEMENTS {
120- for operations in OPERATIONS {
121- for & variant in VEC_VARIANTS {
122- let mut initialized = false ;
123- let runner = tokio:: Runner :: new ( cfg. clone ( ) ) ;
124- c. bench_function (
125- & format ! (
126- "{}/variant={} elements={elements} operations={operations}" ,
127- module_path!( ) ,
128- variant. name( ) ,
129- ) ,
130- |b| {
131- // Setup: populate database (once, on first sample).
132- if !initialized {
133- commonware_runtime:: tokio:: Runner :: new ( cfg. clone ( ) ) . start (
134- |ctx| async move {
135- dispatch_var ! ( ctx, variant, |db| {
136- populate_and_sync(
137- & mut db,
138- elements,
139- operations,
140- make_var_value,
141- )
142- . await ;
143- } ) ;
144- } ,
145- ) ;
146- initialized = true ;
147- }
119+ for ( elements, operations) in CASES {
120+ for & variant in VEC_VARIANTS {
121+ let mut initialized = false ;
122+ let runner = tokio:: Runner :: new ( cfg. clone ( ) ) ;
123+ c. bench_function (
124+ & format ! (
125+ "{}/variant={} elements={elements} operations={operations}" ,
126+ module_path!( ) ,
127+ variant. name( ) ,
128+ ) ,
129+ |b| {
130+ // Setup: populate database (once, on first sample).
131+ if !initialized {
132+ commonware_runtime:: tokio:: Runner :: new ( cfg. clone ( ) ) . start (
133+ |ctx| async move {
134+ dispatch_var ! ( ctx, variant, |db| {
135+ populate_and_sync(
136+ & mut db,
137+ elements,
138+ operations,
139+ make_var_value,
140+ )
141+ . await ;
142+ } ) ;
143+ } ,
144+ ) ;
145+ initialized = true ;
146+ }
148147
149- // Benchmark: measure init time.
150- b. to_async ( & runner) . iter_custom ( |iters| async move {
151- let ctx = context:: get :: < Context > ( ) ;
152- dispatch_var_timed_init ! ( ctx, variant, iters, |db| {
153- assert_ne!( db. bounds( ) . await . end, 0 ) ;
154- } )
155- } ) ;
156- } ,
157- ) ;
148+ // Benchmark: measure init time.
149+ b. to_async ( & runner) . iter_custom ( |iters| async move {
150+ let ctx = context:: get :: < Context > ( ) ;
151+ dispatch_var_timed_init ! ( ctx, variant, iters, |db| {
152+ assert_ne!( db. bounds( ) . await . end, 0 ) ;
153+ } )
154+ } ) ;
155+ } ,
156+ ) ;
158157
159- // Cleanup: destroy database.
160- if initialized {
161- commonware_runtime:: tokio:: Runner :: new ( cfg. clone ( ) ) . start ( |ctx| async move {
162- dispatch_var ! ( ctx, variant, |db| {
163- db. destroy( ) . await . unwrap( ) ;
164- } ) ;
158+ // Cleanup: destroy database.
159+ if initialized {
160+ commonware_runtime:: tokio:: Runner :: new ( cfg. clone ( ) ) . start ( |ctx| async move {
161+ dispatch_var ! ( ctx, variant, |db| {
162+ db. destroy( ) . await . unwrap( ) ;
165163 } ) ;
166- }
164+ } ) ;
167165 }
168166 }
169167 }
0 commit comments