@@ -17,29 +17,34 @@ limitations under the License.
17
17
// Benchmarks are only meaningful and should only run with optimized builds.
18
18
// Unoptimized builds have different performance characteristics and would not provide
19
19
// useful benchmarking data for performance regression testing.
20
- #[ cfg( unoptimized_build) ]
21
- compile_error ! (
22
- "Benchmarks must be run with optimized builds only. Use `cargo bench --release` or `just bench`."
23
- ) ;
24
20
21
+ #[ cfg( optimized_build) ]
25
22
use criterion:: { Criterion , criterion_group, criterion_main} ;
23
+ #[ cfg( optimized_build) ]
26
24
use hyperlight_host:: GuestBinary ;
25
+ #[ cfg( optimized_build) ]
27
26
use hyperlight_host:: sandbox:: {
28
27
Callable , MultiUseSandbox , SandboxConfiguration , UninitializedSandbox ,
29
28
} ;
29
+ #[ cfg( optimized_build) ]
30
30
use hyperlight_host:: sandbox_state:: sandbox:: EvolvableSandbox ;
31
+ #[ cfg( optimized_build) ]
31
32
use hyperlight_host:: sandbox_state:: transition:: Noop ;
33
+ #[ cfg( optimized_build) ]
32
34
use hyperlight_testing:: simple_guest_as_string;
33
35
36
+ #[ cfg( optimized_build) ]
34
37
fn create_uninit_sandbox ( ) -> UninitializedSandbox {
35
38
let path = simple_guest_as_string ( ) . unwrap ( ) ;
36
39
UninitializedSandbox :: new ( GuestBinary :: FilePath ( path) , None ) . unwrap ( )
37
40
}
38
41
42
+ #[ cfg( optimized_build) ]
39
43
fn create_multiuse_sandbox ( ) -> MultiUseSandbox {
40
44
create_uninit_sandbox ( ) . evolve ( Noop :: default ( ) ) . unwrap ( )
41
45
}
42
46
47
+ #[ cfg( optimized_build) ]
43
48
fn guest_call_benchmark ( c : & mut Criterion ) {
44
49
let mut group = c. benchmark_group ( "guest_functions" ) ;
45
50
@@ -87,6 +92,7 @@ fn guest_call_benchmark(c: &mut Criterion) {
87
92
group. finish ( ) ;
88
93
}
89
94
95
+ #[ cfg( optimized_build) ]
90
96
fn guest_call_benchmark_large_param ( c : & mut Criterion ) {
91
97
let mut group = c. benchmark_group ( "guest_functions_with_large_parameters" ) ;
92
98
#[ cfg( target_os = "windows" ) ]
@@ -122,6 +128,7 @@ fn guest_call_benchmark_large_param(c: &mut Criterion) {
122
128
group. finish ( ) ;
123
129
}
124
130
131
+ #[ cfg( optimized_build) ]
125
132
fn sandbox_benchmark ( c : & mut Criterion ) {
126
133
let mut group = c. benchmark_group ( "sandboxes" ) ;
127
134
@@ -161,9 +168,19 @@ fn sandbox_benchmark(c: &mut Criterion) {
161
168
group. finish ( ) ;
162
169
}
163
170
171
+ #[ cfg( optimized_build) ]
164
172
criterion_group ! {
165
173
name = benches;
166
174
config = Criterion :: default ( ) ;
167
175
targets = guest_call_benchmark, sandbox_benchmark, guest_call_benchmark_large_param
168
176
}
177
+
178
+ #[ cfg( optimized_build) ]
169
179
criterion_main ! ( benches) ;
180
+
181
+ // For unoptimized builds, provide a minimal main function that explains benchmarks are not available
182
+ #[ cfg( unoptimized_build) ]
183
+ fn main ( ) {
184
+ eprintln ! ( "Benchmarks are only available in optimized builds. Use `cargo bench --release` or `just bench`." ) ;
185
+ std:: process:: exit ( 1 ) ;
186
+ }
0 commit comments