@@ -17,26 +17,34 @@ limitations under the License.
1717// Benchmarks are only meaningful and should only run with optimized builds. 
1818// Unoptimized builds have different performance characteristics and would not provide 
1919// useful benchmarking data for performance regression testing. 
20- #![ cfg( optimized_build) ]  
2120
21+ #[ cfg( optimized_build) ]  
2222use  criterion:: { Criterion ,  criterion_group,  criterion_main} ; 
23+ #[ cfg( optimized_build) ]  
2324use  hyperlight_host:: GuestBinary ; 
25+ #[ cfg( optimized_build) ]  
2426use  hyperlight_host:: sandbox:: { 
2527    Callable ,  MultiUseSandbox ,  SandboxConfiguration ,  UninitializedSandbox , 
2628} ; 
29+ #[ cfg( optimized_build) ]  
2730use  hyperlight_host:: sandbox_state:: sandbox:: EvolvableSandbox ; 
31+ #[ cfg( optimized_build) ]  
2832use  hyperlight_host:: sandbox_state:: transition:: Noop ; 
33+ #[ cfg( optimized_build) ]  
2934use  hyperlight_testing:: simple_guest_as_string; 
3035
36+ #[ cfg( optimized_build) ]  
3137fn  create_uninit_sandbox ( )  -> UninitializedSandbox  { 
3238    let  path = simple_guest_as_string ( ) . unwrap ( ) ; 
3339    UninitializedSandbox :: new ( GuestBinary :: FilePath ( path) ,  None ) . unwrap ( ) 
3440} 
3541
42+ #[ cfg( optimized_build) ]  
3643fn  create_multiuse_sandbox ( )  -> MultiUseSandbox  { 
3744    create_uninit_sandbox ( ) . evolve ( Noop :: default ( ) ) . unwrap ( ) 
3845} 
3946
47+ #[ cfg( optimized_build) ]  
4048fn  guest_call_benchmark ( c :  & mut  Criterion )  { 
4149    let  mut  group = c. benchmark_group ( "guest_functions" ) ; 
4250
@@ -84,6 +92,7 @@ fn guest_call_benchmark(c: &mut Criterion) {
8492    group. finish ( ) ; 
8593} 
8694
95+ #[ cfg( optimized_build) ]  
8796fn  guest_call_benchmark_large_param ( c :  & mut  Criterion )  { 
8897    let  mut  group = c. benchmark_group ( "guest_functions_with_large_parameters" ) ; 
8998    #[ cfg( target_os = "windows" ) ]  
@@ -119,6 +128,7 @@ fn guest_call_benchmark_large_param(c: &mut Criterion) {
119128    group. finish ( ) ; 
120129} 
121130
131+ #[ cfg( optimized_build) ]  
122132fn  sandbox_benchmark ( c :  & mut  Criterion )  { 
123133    let  mut  group = c. benchmark_group ( "sandboxes" ) ; 
124134
@@ -158,10 +168,21 @@ fn sandbox_benchmark(c: &mut Criterion) {
158168    group. finish ( ) ; 
159169} 
160170
171+ #[ cfg( optimized_build) ]  
161172criterion_group !  { 
162173    name = benches; 
163174    config = Criterion :: default ( ) ; 
164175    targets = guest_call_benchmark,  sandbox_benchmark,  guest_call_benchmark_large_param
165176} 
166177
178+ #[ cfg( optimized_build) ]  
167179criterion_main ! ( benches) ; 
180+ 
181+ // Provide a fallback main function for unoptimized builds 
182+ // This prevents compilation errors while providing a clear message 
183+ #[ cfg( unoptimized_build) ]  
184+ fn  main ( )  { 
185+     panic ! ( 
186+         "Benchmarks must be run with optimized builds only. Use `cargo bench --release` or `just bench`." 
187+     ) ; 
188+ } 
0 commit comments