Skip to content

Commit a725839

Browse files
Copilotjsturtevant
andcommitted
Enforce release builds for benchmarks in Justfile and source code
Co-authored-by: jsturtevant <[email protected]> Signed-off-by: Simon Davies <[email protected]>
1 parent cd4c18b commit a725839

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

Justfile

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -326,11 +326,15 @@ bench-download os hypervisor cpu tag="":
326326
tar -zxvf target/benchmarks_{{ os }}_{{ hypervisor }}_{{ cpu }}.tar.gz -C target/criterion/ --strip-components=1
327327

328328
# Warning: compares to and then OVERWRITES the given baseline
329-
bench-ci baseline target=default-target features="":
330-
cargo bench --profile={{ if target == "debug" { "dev" } else { target } }} {{ if features =="" {''} else { "--features " + features } }} -- --verbose --save-baseline {{ baseline }}
331-
332-
bench target=default-target features="":
333-
cargo bench --profile={{ if target == "debug" { "dev" } else { target } }} {{ if features =="" {''} else { "--features " + features } }} -- --verbose
329+
bench-ci baseline target="release" features="":
330+
@# Benchmarks should only be run with release builds for meaningful results
331+
@if [ "{{ target }}" != "release" ]; then echo "Error: Benchmarks can only be run with release builds. Use 'just bench-ci <baseline> release' instead."; exit 1; fi
332+
cargo bench --profile=release {{ if features =="" {''} else { "--features " + features } }} -- --verbose --save-baseline {{ baseline }}
333+
334+
bench target="release" features="":
335+
@# Benchmarks should only be run with release builds for meaningful results
336+
@if [ "{{ target }}" != "release" ]; then echo "Error: Benchmarks can only be run with release builds. Use 'just bench release' instead."; exit 1; fi
337+
cargo bench --profile=release {{ if features =="" {''} else { "--features " + features } }} -- --verbose
334338

335339
###############
336340
### FUZZING ###

docs/benchmarking-hyperlight.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,6 @@ Found 1 outliers among 100 measurements (1.00%)
7272
7373
## Running benchmarks locally
7474
75-
Use `just bench [debug/release]` parameter to run benchmarks. Comparing local benchmarks results to github-saved benchmarks doesn't make much sense, since you'd be using different hardware, but you can use `just bench-download os hypervisor [tag] ` to download and extract the GitHub release benchmarks to the correct place folder. You can then run `just bench-ci main` to compare to (and overwrite) the previous release benchmarks. Note that `main` is the name of the baselines stored in GitHub.
75+
Use `just bench` to run benchmarks with release builds (the only supported configuration). Comparing local benchmark results to github-saved benchmarks doesn't make much sense, since you'd be using different hardware, but you can use `just bench-download os hypervisor [tag] ` to download and extract the GitHub release benchmarks to the correct place folder. You can then run `just bench-ci main` to compare to (and overwrite) the previous release benchmarks. Note that `main` is the name of the baselines stored in GitHub.
76+
77+
**Important**: Benchmarks can only be run with release builds to ensure meaningful performance measurements. Debug builds are not supported for benchmarking.

src/hyperlight_host/benches/benchmarks.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17+
// Ensure benchmarks only run with release builds for meaningful performance measurements
18+
#[cfg(debug_assertions)]
19+
compile_error!(
20+
"Benchmarks can only be run with release builds. Use '--release' flag when running benchmarks."
21+
);
22+
1723
use criterion::{Criterion, criterion_group, criterion_main};
1824
use hyperlight_host::GuestBinary;
1925
use hyperlight_host::sandbox::{MultiUseSandbox, SandboxConfiguration, UninitializedSandbox};

0 commit comments

Comments
 (0)