1- use criterion:: { criterion_group, criterion_main, Criterion , BenchmarkId } ;
2- use osvm:: utils:: ebpf_deploy:: {
3- load_program, load_program_id, DeployConfig , RpcClientCache ,
4- } ;
1+ use criterion:: { criterion_group, criterion_main, BenchmarkId , Criterion } ;
2+ use osvm:: utils:: ebpf_deploy:: { load_program, load_program_id, DeployConfig , RpcClientCache } ;
53use std:: fs:: File ;
64use std:: io:: Write ;
75use std:: time:: { Duration , Instant } ;
@@ -10,65 +8,61 @@ use tempfile::tempdir;
108/// Benchmark program loading performance
119fn benchmark_load_program ( c : & mut Criterion ) {
1210 let dir = tempdir ( ) . unwrap ( ) ;
13-
11+
1412 // Create test programs of different sizes
1513 let sizes = vec ! [
16- ( "small" , 10_000 ) , // 10KB
17- ( "medium" , 100_000 ) , // 100KB
18- ( "large" , 1_000_000 ) , // 1MB
14+ ( "small" , 10_000 ) , // 10KB
15+ ( "medium" , 100_000 ) , // 100KB
16+ ( "large" , 1_000_000 ) , // 1MB
1917 ( "xlarge" , 2_000_000 ) , // 2MB
2018 ] ;
21-
19+
2220 let mut group = c. benchmark_group ( "load_program" ) ;
23-
21+
2422 for ( name, size) in sizes {
2523 let program_path = dir. path ( ) . join ( format ! ( "program_{}.so" , name) ) ;
2624 let program_data = vec ! [ 0u8 ; size] ;
2725 let mut file = File :: create ( & program_path) . unwrap ( ) ;
2826 file. write_all ( & program_data) . unwrap ( ) ;
29-
27+
3028 group. benchmark_with_input (
3129 BenchmarkId :: new ( "load_program" , name) ,
3230 & program_path. to_string_lossy ( ) . to_string ( ) ,
3331 |b, path| {
34- b. iter ( || {
35- load_program ( path) . unwrap ( )
36- } ) ;
32+ b. iter ( || load_program ( path) . unwrap ( ) ) ;
3733 } ,
3834 ) ;
3935 }
40-
36+
4137 group. finish ( ) ;
4238}
4339
4440/// Benchmark program ID loading performance
4541fn benchmark_load_program_id ( c : & mut Criterion ) {
4642 let dir = tempdir ( ) . unwrap ( ) ;
4743 let program_id_file = dir. path ( ) . join ( "program_id.json" ) ;
48-
44+
4945 // Create test program ID file
5046 let program_id_content = r#"{"programId": "HN4tEEGheziD9dqcWg4xZd29htcerjXKGoGiQXM5hxiS"}"# ;
5147 let mut file = File :: create ( & program_id_file) . unwrap ( ) ;
5248 file. write_all ( program_id_content. as_bytes ( ) ) . unwrap ( ) ;
53-
49+
5450 c. bench_function ( "load_program_id" , |b| {
55- b. iter ( || {
56- load_program_id ( program_id_file. to_str ( ) . unwrap ( ) ) . unwrap ( )
57- } ) ;
51+ b. iter ( || load_program_id ( program_id_file. to_str ( ) . unwrap ( ) ) . unwrap ( ) ) ;
5852 } ) ;
5953}
6054
6155/// Benchmark RPC client cache performance
6256fn benchmark_rpc_client_cache ( c : & mut Criterion ) {
6357 let mut group = c. benchmark_group ( "rpc_client_cache" ) ;
64-
58+
6559 // Test cache performance with multiple URLs
6660 let urls = vec ! [
6761 "https://api.devnet.solana.com" ,
68- "https://api.testnet.solana.com" ,
62+ "https://api.testnet.solana.com" ,
6963 "https://api.mainnet-beta.solana.com" ,
7064 ] ;
71-
65+
7266 group. bench_function ( "cache_miss" , |b| {
7367 b. iter ( || {
7468 let mut cache = RpcClientCache :: new ( ) ;
@@ -77,40 +71,38 @@ fn benchmark_rpc_client_cache(c: &mut Criterion) {
7771 }
7872 } ) ;
7973 } ) ;
80-
74+
8175 group. bench_function ( "cache_hit" , |b| {
8276 let mut cache = RpcClientCache :: new ( ) ;
8377 // Pre-populate cache
8478 for url in & urls {
8579 cache. get_client ( url) ;
8680 }
87-
81+
8882 b. iter ( || {
8983 for url in & urls {
9084 cache. get_client ( url) ;
9185 }
9286 } ) ;
9387 } ) ;
94-
88+
9589 group. finish ( ) ;
9690}
9791
9892/// Benchmark deployment configuration creation
9993fn benchmark_deploy_config_creation ( c : & mut Criterion ) {
10094 c. bench_function ( "deploy_config_creation" , |b| {
101- b. iter ( || {
102- DeployConfig {
103- binary_path : "program.so" . to_string ( ) ,
104- program_id_path : "program_id.json" . to_string ( ) ,
105- owner_path : "owner.json" . to_string ( ) ,
106- fee_payer_path : "fee_payer.json" . to_string ( ) ,
107- publish_idl : true ,
108- idl_file_path : Some ( "idl.json" . to_string ( ) ) ,
109- network_selection : "all" . to_string ( ) ,
110- json_output : false ,
111- retry_attempts : 3 ,
112- confirm_large_binaries : false ,
113- }
95+ b. iter ( || DeployConfig {
96+ binary_path : "program.so" . to_string ( ) ,
97+ program_id_path : "program_id.json" . to_string ( ) ,
98+ owner_path : "owner.json" . to_string ( ) ,
99+ fee_payer_path : "fee_payer.json" . to_string ( ) ,
100+ publish_idl : true ,
101+ idl_file_path : Some ( "idl.json" . to_string ( ) ) ,
102+ network_selection : "all" . to_string ( ) ,
103+ json_output : false ,
104+ retry_attempts : 3 ,
105+ confirm_large_binaries : false ,
114106 } ) ;
115107 } ) ;
116108}
@@ -119,7 +111,7 @@ fn benchmark_deploy_config_creation(c: &mut Criterion) {
119111fn benchmark_json_operations ( c : & mut Criterion ) {
120112 use osvm:: utils:: ebpf_deploy:: DeploymentResult ;
121113 use solana_sdk:: pubkey:: Pubkey ;
122-
114+
123115 let result = DeploymentResult {
124116 network : "devnet" . to_string ( ) ,
125117 program_id : Pubkey :: new_unique ( ) ,
@@ -129,65 +121,61 @@ fn benchmark_json_operations(c: &mut Criterion) {
129121 retries_attempted : 3 ,
130122 duration_ms : 5000 ,
131123 } ;
132-
124+
133125 let mut group = c. benchmark_group ( "json_operations" ) ;
134-
126+
135127 group. bench_function ( "serialize" , |b| {
136- b. iter ( || {
137- serde_json:: to_string ( & result) . unwrap ( )
138- } ) ;
128+ b. iter ( || serde_json:: to_string ( & result) . unwrap ( ) ) ;
139129 } ) ;
140-
130+
141131 let json_str = serde_json:: to_string ( & result) . unwrap ( ) ;
142132 group. bench_function ( "deserialize" , |b| {
143133 b. iter ( || {
144134 let _: DeploymentResult = serde_json:: from_str ( & json_str) . unwrap ( ) ;
145135 } ) ;
146136 } ) ;
147-
137+
148138 group. finish ( ) ;
149139}
150140
151141/// Benchmark file operations for deployment
152142fn benchmark_file_operations ( c : & mut Criterion ) {
153143 let dir = tempdir ( ) . unwrap ( ) ;
154-
144+
155145 // Create test files of various sizes
156146 let file_sizes = vec ! [ 1_000 , 10_000 , 100_000 , 1_000_000 ] ;
157147 let mut test_files = Vec :: new ( ) ;
158-
148+
159149 for size in file_sizes {
160150 let file_path = dir. path ( ) . join ( format ! ( "test_{}.dat" , size) ) ;
161151 let data = vec ! [ 0u8 ; size] ;
162152 let mut file = File :: create ( & file_path) . unwrap ( ) ;
163153 file. write_all ( & data) . unwrap ( ) ;
164154 test_files. push ( ( size, file_path) ) ;
165155 }
166-
156+
167157 let mut group = c. benchmark_group ( "file_operations" ) ;
168-
158+
169159 for ( size, file_path) in test_files {
170160 group. benchmark_with_input (
171161 BenchmarkId :: new ( "read_file" , size) ,
172162 & file_path,
173163 |b, path| {
174- b. iter ( || {
175- std:: fs:: read ( path) . unwrap ( )
176- } ) ;
164+ b. iter ( || std:: fs:: read ( path) . unwrap ( ) ) ;
177165 } ,
178166 ) ;
179167 }
180-
168+
181169 group. finish ( ) ;
182170}
183171
184172/// Benchmark memory usage and allocation patterns
185173fn benchmark_memory_allocation ( c : & mut Criterion ) {
186174 let mut group = c. benchmark_group ( "memory_allocation" ) ;
187-
175+
188176 // Test vector allocation for different program sizes
189177 let sizes = vec ! [ 10_000 , 100_000 , 1_000_000 , 5_000_000 ] ;
190-
178+
191179 for size in sizes {
192180 group. benchmark_with_input (
193181 BenchmarkId :: new ( "vec_allocation" , size) ,
@@ -199,7 +187,7 @@ fn benchmark_memory_allocation(c: &mut Criterion) {
199187 } ,
200188 ) ;
201189 }
202-
190+
203191 group. finish ( ) ;
204192}
205193
@@ -214,4 +202,4 @@ criterion_group!(
214202 benchmark_memory_allocation
215203) ;
216204
217- criterion_main ! ( benches) ;
205+ criterion_main ! ( benches) ;
0 commit comments