Skip to content

Commit 4645962

Browse files
author
Sherry Fan
committed
is this better for std
1 parent 4ef8f65 commit 4645962

File tree

5 files changed

+31
-5
lines changed

5 files changed

+31
-5
lines changed

services_benchmark_test/Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,15 @@ cfg-if = { workspace = true }
2525
log = { workspace = true }
2626
r-efi = { workspace = true }
2727
rolling-stats = { workspace = true }
28-
uefi = { version = "0.36.0", features = ["alloc", "logger", "global_allocator"] }
2928
uuid = { workspace = true }
3029

3130
patina = { workspace = true }
3231

32+
[target.'cfg(target_os = "uefi")'.dependencies]
33+
uefi = { version = "0.36.0", features = ["alloc", "logger", "global_allocator"] }
34+
35+
[target.'cfg(not(target_os = "uefi"))'.dependencies]
36+
uefi = { version = "0.36.0", default-features = false }
37+
3338
[dev-dependencies]
3439
mockall = "0.13.0"

services_benchmark_test/src/bench/controller.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1+
#[cfg(target_os = "uefi")]
12
use alloc::{boxed::Box, vec};
3+
4+
#[cfg(not(target_os = "uefi"))]
5+
use std::{boxed::Box, vec};
6+
27
use mu_rust_helpers::perf_timer::{Arch, ArchFunctionality as _};
38
use patina::boot_services::BootServices;
49
use r_efi::efi;
510
use rolling_stats::Stats;
611

712
use crate::{
813
BOOT_SERVICES,
9-
bench::{TEST_GUID1, TEST_GUID2, TestProtocol1, TestProtocol2},
14+
bench::{TestProtocol1, TestProtocol2},
1015
error::BenchError,
1116
};
1217

services_benchmark_test/src/bench/event.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
#[cfg(target_os = "uefi")]
12
use alloc::vec::Vec;
3+
4+
#[cfg(not(target_os = "uefi"))]
5+
use std::vec::Vec;
6+
27
use core::{ffi::c_void, ptr};
38

49
use mu_rust_helpers::perf_timer::{Arch, ArchFunctionality as _};

services_benchmark_test/src/bench/protocol.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,17 @@ use crate::{
1111
error::BenchError,
1212
};
1313

14+
#[cfg(target_os = "uefi")]
15+
use alloc::boxed::Box;
16+
17+
#[cfg(not(target_os = "uefi"))]
18+
use std::boxed::Box;
19+
1420
/// Benchmarks protocol installation performance.
1521
pub(crate) fn bench_install_protocol_interface(
1622
_handle: efi::Handle,
1723
num_calls: usize,
1824
) -> Result<Stats<f64>, BenchError> {
19-
let protocol_interface = 0x1234 as *mut c_void;
2025
let mut stats: Stats<f64> = Stats::new();
2126
for _ in 0..num_calls {
2227
let start = Arch::cpu_count();

services_benchmark_test/src/lib.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,15 @@ const COL_WIDTHS: [usize; 8] = [32, 14, 12, 15, 15, 12, 12, 12];
2828
/// Global instance of UEFI Boot Services.
2929
pub static BOOT_SERVICES: StandardBootServices = StandardBootServices::new_uninit();
3030

31+
#[cfg(target_os = "uefi")]
3132
extern crate alloc;
32-
use alloc::{string::ToString, vec::Vec};
33+
34+
#[cfg(target_os = "uefi")]
35+
use alloc::{string::String, string::ToString, vec::Vec};
36+
37+
#[cfg(not(target_os = "uefi"))]
38+
use std::{string::String, string::ToString, vec::Vec};
39+
3340
use core::fmt::Write;
3441
use mu_rust_helpers::perf_timer::{Arch, ArchFunctionality as _};
3542
use rolling_stats::Stats;
@@ -38,7 +45,6 @@ use patina::boot_services::StandardBootServices;
3845
use r_efi::efi;
3946

4047
use crate::{error::BenchError, measure::BENCH_FNS};
41-
use alloc::string::String;
4248

4349
pub fn bench_start(handle: efi::Handle) -> Result<(), BenchError> {
4450
log::info!("Starting Services Benchmark Test...");

0 commit comments

Comments
 (0)