Skip to content

Commit 67de11d

Browse files
committed
Update benchmarks
Signed-off-by: Simon Davies <[email protected]>
1 parent 9117951 commit 67de11d

File tree

1 file changed

+39
-14
lines changed

1 file changed

+39
-14
lines changed

src/hyperlight_host/benches/benchmarks.rs

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ fn sandbox_heap_size_benchmark(c: &mut Criterion) {
208208
fn guest_call_heap_size_benchmark(c: &mut Criterion) {
209209
let mut group = c.benchmark_group("guest_call_heap_sizes");
210210

211-
// Helper function to create sandbox with specific heap size and call a guest function
212-
let create_sandbox_and_call = |heap_size_mb: Option<u64>| {
211+
// Helper function to create sandbox with specific heap size
212+
let create_sandbox_with_heap_size = |heap_size_mb: Option<u64>| {
213213
let path = simple_guest_as_string().unwrap();
214214
let config = if let Some(size_mb) = heap_size_mb {
215215
let mut config = SandboxConfiguration::default();
@@ -221,42 +221,67 @@ fn guest_call_heap_size_benchmark(c: &mut Criterion) {
221221

222222
let uninit_sandbox =
223223
UninitializedSandbox::new(GuestBinary::FilePath(path), config).unwrap();
224-
let mut sandbox = uninit_sandbox.evolve(Noop::default()).unwrap();
225-
226-
// Call the Echo function to test performance with different heap sizes
227-
sandbox
228-
.call_guest_function_by_name::<String>("Echo", "hello\n".to_string())
229-
.unwrap()
224+
uninit_sandbox.evolve(Noop::default()).unwrap()
230225
};
231226

232227
// Benchmark guest function call with default heap size
233228
group.bench_function("guest_call_default_heap", |b| {
234-
b.iter(|| create_sandbox_and_call(None));
229+
let mut sandbox = create_sandbox_with_heap_size(None);
230+
b.iter(|| {
231+
sandbox
232+
.call_guest_function_by_name::<String>("Echo", "hello\n".to_string())
233+
.unwrap()
234+
});
235235
});
236236

237237
// Benchmark guest function call with 50MB heap
238238
group.bench_function("guest_call_50mb_heap", |b| {
239-
b.iter(|| create_sandbox_and_call(Some(50)));
239+
let mut sandbox = create_sandbox_with_heap_size(Some(50));
240+
b.iter(|| {
241+
sandbox
242+
.call_guest_function_by_name::<String>("Echo", "hello\n".to_string())
243+
.unwrap()
244+
});
240245
});
241246

242247
// Benchmark guest function call with 100MB heap
243248
group.bench_function("guest_call_100mb_heap", |b| {
244-
b.iter(|| create_sandbox_and_call(Some(100)));
249+
let mut sandbox = create_sandbox_with_heap_size(Some(100));
250+
b.iter(|| {
251+
sandbox
252+
.call_guest_function_by_name::<String>("Echo", "hello\n".to_string())
253+
.unwrap()
254+
});
245255
});
246256

247257
// Benchmark guest function call with 250MB heap
248258
group.bench_function("guest_call_250mb_heap", |b| {
249-
b.iter(|| create_sandbox_and_call(Some(250)));
259+
let mut sandbox = create_sandbox_with_heap_size(Some(250));
260+
b.iter(|| {
261+
sandbox
262+
.call_guest_function_by_name::<String>("Echo", "hello\n".to_string())
263+
.unwrap()
264+
});
250265
});
251266

252267
// Benchmark guest function call with 500MB heap
253268
group.bench_function("guest_call_500mb_heap", |b| {
254-
b.iter(|| create_sandbox_and_call(Some(500)));
269+
let mut sandbox = create_sandbox_with_heap_size(Some(500));
270+
b.iter(|| {
271+
sandbox
272+
.call_guest_function_by_name::<String>("Echo", "hello\n".to_string())
273+
.unwrap()
274+
});
255275
});
256276

257277
// Benchmark guest function call with 995MB heap
258278
group.bench_function("guest_call_995mb_heap", |b| {
259-
b.iter(|| create_sandbox_and_call(Some(995)));
279+
let mut sandbox = create_sandbox_with_heap_size(Some(995));
280+
b.iter(|| {
281+
sandbox
282+
.call_guest_function_by_name::<String>("Echo", "hello\n".to_string())
283+
.unwrap()
284+
});
260285
});
261286

262287
group.finish();

0 commit comments

Comments
 (0)