@@ -15,6 +15,8 @@ limitations under the License.
1515*/
1616
1717use 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 } ;
1820use hyperlight_host:: GuestBinary ;
1921use hyperlight_host:: sandbox:: { MultiUseSandbox , SandboxConfiguration , UninitializedSandbox } ;
2022use hyperlight_testing:: simple_guest_as_string;
@@ -133,9 +135,51 @@ fn sandbox_benchmark(c: &mut Criterion) {
133135 group. finish ( ) ;
134136}
135137
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+
136180criterion_group ! {
137181 name = benches;
138182 config = Criterion :: default ( ) ;
139- targets = guest_call_benchmark, sandbox_benchmark, guest_call_benchmark_large_param
183+ targets = guest_call_benchmark, sandbox_benchmark, guest_call_benchmark_large_param, function_call_serialization_benchmark
140184}
141185criterion_main ! ( benches) ;
0 commit comments