Skip to content

Commit 3472133

Browse files
committed
Update benchmarks to make slow benchmark take less samples on Windows
Signed-off-by: Simon Davies <[email protected]>
1 parent e280a60 commit 3472133

File tree

1 file changed

+26
-18
lines changed

1 file changed

+26
-18
lines changed

src/hyperlight_host/benches/benchmarks.rs

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,31 @@ fn guest_call_benchmark(c: &mut Criterion) {
5959
});
6060
});
6161

62+
// Benchmarks a guest function call calling into the host.
63+
// The benchmark does **not** include the time to reset the sandbox memory after the call.
64+
group.bench_function("guest_call_with_call_to_host_function", |b| {
65+
let mut uninitialized_sandbox = create_uninit_sandbox();
66+
67+
// Define a host function that adds two integers and register it.
68+
uninitialized_sandbox
69+
.register("HostAdd", |a: i32, b: i32| Ok(a + b))
70+
.unwrap();
71+
72+
let multiuse_sandbox: MultiUseSandbox =
73+
uninitialized_sandbox.evolve(Noop::default()).unwrap();
74+
let mut call_ctx = multiuse_sandbox.new_call_context();
75+
76+
b.iter(|| call_ctx.call::<i32>("Add", (1_i32, 41_i32)).unwrap());
77+
});
78+
79+
group.finish();
80+
}
81+
82+
fn guest_call_benchmark_large_param(c: &mut Criterion) {
83+
let mut group = c.benchmark_group("guest_functions_with_large_parameters");
84+
#[cfg(target_os = "windows")]
85+
group.sample_size(10); // This benchark is very slow on Windows, so we reduce the sample size to avoid long test runs.
86+
6287
// This benchmark includes time to first clone a vector and string, so it is not a "pure' benchmark of the guest call, but it's still useful
6388
group.bench_function("guest_call_with_large_parameters", |b| {
6489
const SIZE: usize = 50 * 1024 * 1024; // 50 MB
@@ -86,23 +111,6 @@ fn guest_call_benchmark(c: &mut Criterion) {
86111
});
87112
});
88113

89-
// Benchmarks a guest function call calling into the host.
90-
// The benchmark does **not** include the time to reset the sandbox memory after the call.
91-
group.bench_function("guest_call_with_call_to_host_function", |b| {
92-
let mut uninitialized_sandbox = create_uninit_sandbox();
93-
94-
// Define a host function that adds two integers and register it.
95-
uninitialized_sandbox
96-
.register("HostAdd", |a: i32, b: i32| Ok(a + b))
97-
.unwrap();
98-
99-
let multiuse_sandbox: MultiUseSandbox =
100-
uninitialized_sandbox.evolve(Noop::default()).unwrap();
101-
let mut call_ctx = multiuse_sandbox.new_call_context();
102-
103-
b.iter(|| call_ctx.call::<i32>("Add", (1_i32, 41_i32)).unwrap());
104-
});
105-
106114
group.finish();
107115
}
108116

@@ -148,6 +156,6 @@ fn sandbox_benchmark(c: &mut Criterion) {
148156
criterion_group! {
149157
name = benches;
150158
config = Criterion::default();
151-
targets = guest_call_benchmark, sandbox_benchmark
159+
targets = guest_call_benchmark, sandbox_benchmark, guest_call_benchmark_large_param
152160
}
153161
criterion_main!(benches);

0 commit comments

Comments
 (0)