Skip to content

Commit

Permalink
add bench for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
wiiznokes committed Dec 4, 2023
1 parent d121e6e commit 2e36997
Showing 1 changed file with 57 additions and 3 deletions.
60 changes: 57 additions & 3 deletions hardware/src/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ const CHECK_RESPONSE: &str = "fan-control-ok";

impl HardwareBridge for WindowsBridge {
fn generate_hardware() -> (Hardware, HardwareBridgeT) {
let handle = process::Command::new("./target/lhm/LibreHardwareMonitorWrapper")
.spawn()
.unwrap();
#[cfg(test)]
let path = "./../target/lhm/LibreHardwareMonitorWrapper";
#[cfg(not(test))]
let path = "./target/lhm/LibreHardwareMonitorWrapper";

let handle = process::Command::new(path).spawn().unwrap();

let mut hardware = Hardware::default();

Expand Down Expand Up @@ -260,3 +263,54 @@ fn is_little_endian() -> bool {
// If the byte is 1, the system is little-endian; otherwise, it's big-endian
byte == 1
}

#[cfg(test)]
mod test {
use super::WindowsBridge;
use crate::{HardwareBridge, HardwareBridgeT};
use std::time::Instant;

#[test]
fn test_time() {
let f = || {
let (hardware, mut bridge) = WindowsBridge::generate_hardware();

for h in &hardware.controls {
get_value(&mut bridge, &h.internal_index, &h.name);
}
for h in &hardware.temps {
get_value(&mut bridge, &h.internal_index, &h.name);
}
for h in &hardware.fans {
get_value(&mut bridge, &h.internal_index, &h.name);
}
};
bench(f, "all");
}

fn get_value(bridge: &mut HardwareBridgeT, index: &usize, name: &str) {
bench(
|| {
match bridge.get_value(index) {
Ok(value) => {
println!("value of control {} = {}", name, value);
}
Err(e) => {
println!("error of control {} = {:?}", name, e);
}
};
},
"get_value",
);
}

fn bench(f: impl FnOnce(), info: &str) {
let now = Instant::now();
f();
println!(
"fun: {}, time taken: {} millis",
info,
now.elapsed().as_millis()
);
}
}

0 comments on commit 2e36997

Please sign in to comment.