refactor: remove the software timing measures since they are not reliable

This commit is contained in:
cscherr 2025-08-06 09:43:04 +02:00
parent f162fe8734
commit f944cce39d
Signed by: cscherrNT
GPG key ID: 8E2B45BC51A27EA7

View file

@ -6,15 +6,6 @@ use hal::{
prelude::*,
};
macro_rules! display_results {
($name:expr, $rust_cycles:expr, $c_cycles:expr) => {
info!(
"Benchmark {}:\nRust\t: {}\nC\t: {}",
$name, $rust_cycles, $c_cycles
)
};
}
#[inline]
pub fn bench(pin: &mut Pin<Output<PushPull>>, delay: &mut Delay) {
bench_delay(pin, delay);
@ -22,40 +13,31 @@ pub fn bench(pin: &mut Pin<Output<PushPull>>, delay: &mut Delay) {
}
fn bench_delay(pin: &mut Pin<Output<PushPull>>, delay: &mut Delay) {
let short_sleep = time_exec(pin, || delay.delay_ms(20u32));
let long_sleep = time_exec(pin, || delay.delay_ms(50u32));
info!("Bench for short sleep: {}", short_sleep);
info!("Bench for long sleep: {}", long_sleep);
time_exec(pin, || delay.delay_ms(20u32));
time_exec(pin, || delay.delay_ms(50u32));
}
fn time_exec<F>(pin: &mut Pin<Output<PushPull>>, mut f: F) -> u32
fn time_exec<F>(pin: &mut Pin<Output<PushPull>>, mut f: F)
where
F: FnMut(),
{
info!("Running the requested function 50 times and returning the average");
const RUNS: u32 = 50;
let start = cortex_m::peripheral::SYST::get_current();
pin.set_high().expect("could not set pun to high");
for _ in 0..RUNS {
f();
}
pin.set_low().expect("could not set pun to low");
let end = cortex_m::peripheral::SYST::get_current();
// the timer counts down
info!("Start: {}\nEnd: {}", start, end);
let total = start.wrapping_sub(end);
total / RUNS
}
fn bench_crc(pin: &mut Pin<Output<PushPull>>, delay: &mut Delay) {
const DATA: &[u8] = b"hello world AAAAAAAAAAAAAAAAAAAAAAA";
delay.delay_ms(50_u32);
let native = time_exec(pin, || {
time_exec(pin, || {
Crc32Rust::checksum(DATA);
});
delay.delay_ms(50_u32);
let c_code = time_exec(pin, || {
time_exec(pin, || {
Crc32C::checksum(DATA);
});
display_results!("CRC", native, c_code);
}