@@ -15,9 +15,11 @@ limitations under the License.
15
15
*/
16
16
17
17
use criterion:: { Criterion , criterion_group, criterion_main} ;
18
+ use hyperlight_common:: flatbuffer_wrappers:: function_call:: { FunctionCall , FunctionCallType } ;
19
+ use hyperlight_common:: flatbuffer_wrappers:: function_types:: { ParameterValue , ReturnType } ;
18
20
use hyperlight_host:: GuestBinary ;
19
21
use hyperlight_host:: sandbox:: { MultiUseSandbox , SandboxConfiguration , UninitializedSandbox } ;
20
- use hyperlight_testing:: simple_guest_as_string;
22
+ use hyperlight_testing:: { c_simple_guest_as_string , simple_guest_as_string} ;
21
23
22
24
fn create_uninit_sandbox ( ) -> UninitializedSandbox {
23
25
let path = simple_guest_as_string ( ) . unwrap ( ) ;
@@ -133,9 +135,85 @@ fn sandbox_benchmark(c: &mut Criterion) {
133
135
group. finish ( ) ;
134
136
}
135
137
138
+ fn function_call_serialization_benchmark ( c : & mut Criterion ) {
139
+ let mut group = c. benchmark_group ( "function_call_serialization" ) ;
140
+
141
+ let function_call = FunctionCall :: new (
142
+ "TestFunction" . to_string ( ) ,
143
+ Some ( vec ! [
144
+ ParameterValue :: VecBytes ( vec![ 1 ; 10 * 1024 * 1024 ] ) ,
145
+ ParameterValue :: String ( String :: from_utf8( vec![ 2 ; 10 * 1024 * 1024 ] ) . unwrap( ) ) ,
146
+ ParameterValue :: Int ( 42 ) ,
147
+ ParameterValue :: UInt ( 100 ) ,
148
+ ParameterValue :: Long ( 1000 ) ,
149
+ ParameterValue :: ULong ( 2000 ) ,
150
+ ParameterValue :: Float ( 521521.53 ) ,
151
+ ParameterValue :: Double ( 432.53 ) ,
152
+ ParameterValue :: Bool ( true ) ,
153
+ ParameterValue :: VecBytes ( vec![ 1 ; 10 * 1024 * 1024 ] ) ,
154
+ ParameterValue :: String ( String :: from_utf8( vec![ 2 ; 10 * 1024 * 1024 ] ) . unwrap( ) ) ,
155
+ ] ) ,
156
+ FunctionCallType :: Guest ,
157
+ ReturnType :: Int ,
158
+ ) ;
159
+
160
+ let serialized_bytes: Vec < u8 > = function_call. clone ( ) . try_into ( ) . unwrap ( ) ;
161
+
162
+ group. bench_function ( "serialize_function_call" , |b| {
163
+ b. iter_with_setup (
164
+ || function_call. clone ( ) ,
165
+ |fc| {
166
+ let _serialized: Vec < u8 > = fc. try_into ( ) . unwrap ( ) ;
167
+ } ,
168
+ ) ;
169
+ } ) ;
170
+
171
+ group. bench_function ( "deserialize_function_call" , |b| {
172
+ b. iter ( || {
173
+ let _deserialized: FunctionCall = serialized_bytes. as_slice ( ) . try_into ( ) . unwrap ( ) ;
174
+ } ) ;
175
+ } ) ;
176
+
177
+ group. finish ( ) ;
178
+ }
179
+
180
+ #[ allow( clippy:: disallowed_macros) ]
181
+ fn sample_workloads_benchmark ( c : & mut Criterion ) {
182
+ let mut group = c. benchmark_group ( "sample_workloads" ) ;
183
+
184
+ fn bench_24k_in_8k_out ( b : & mut criterion:: Bencher , guest_path : String ) {
185
+ let mut cfg = SandboxConfiguration :: default ( ) ;
186
+ cfg. set_input_data_size ( 25 * 1024 ) ;
187
+
188
+ let mut sandbox = UninitializedSandbox :: new ( GuestBinary :: FilePath ( guest_path) , Some ( cfg) )
189
+ . unwrap ( )
190
+ . evolve ( )
191
+ . unwrap ( ) ;
192
+
193
+ b. iter_with_setup (
194
+ || vec ! [ 1 ; 24 * 1024 ] ,
195
+ |input| {
196
+ let ret: Vec < u8 > = sandbox. call ( "24K_in_8K_out" , ( input, ) ) . unwrap ( ) ;
197
+ assert_eq ! ( ret. len( ) , 8 * 1024 , "Expected output length to be 8K" ) ;
198
+ std:: hint:: black_box ( ret) ;
199
+ } ,
200
+ ) ;
201
+ }
202
+
203
+ group. bench_function ( "24K_in_8K_out_c" , |b| {
204
+ bench_24k_in_8k_out ( b, c_simple_guest_as_string ( ) . unwrap ( ) ) ;
205
+ } ) ;
206
+
207
+ group. bench_function ( "24K_in_8K_out_rust" , |b| {
208
+ bench_24k_in_8k_out ( b, simple_guest_as_string ( ) . unwrap ( ) ) ;
209
+ } ) ;
210
+
211
+ group. finish ( ) ;
212
+ }
213
+
136
214
criterion_group ! {
137
215
name = benches;
138
216
config = Criterion :: default ( ) ;
139
- targets = guest_call_benchmark, sandbox_benchmark, guest_call_benchmark_large_param
217
+ targets = guest_call_benchmark, sandbox_benchmark, guest_call_benchmark_large_param, function_call_serialization_benchmark , sample_workloads_benchmark
140
218
}
141
219
criterion_main ! ( benches) ;
0 commit comments