Skip to content

Commit

Permalink
benches: Add benchmark using criterion
Browse files Browse the repository at this point in the history
  • Loading branch information
RaulTrombin authored and patrickelectric committed Oct 23, 2023
1 parent 3e8e480 commit 47c08c6
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions benches/bench.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
use criterion::{criterion_group, criterion_main, Criterion};
use navigator_rs::{AdcChannel, Navigator, PwmChannel, UserLed};

fn navigator_benchmark(c: &mut Criterion) {
#[macro_export]
macro_rules! bench {
($bench_fn:ident($($arg:tt)*)) => {
let mut nav = Navigator::new();
nav.init();
c.bench_function(stringify!($bench_fn), |b| b.iter(|| nav.$bench_fn($($arg)*)));
}}

// Navigator creation benchmark
c.bench_function("new", |b| b.iter(|| Navigator::new()));

// Benchmark Inputs
bench!(init());

bench!(read_adc(AdcChannel::Ch0));
bench!(read_adc_all());

bench!(read_accel());
bench!(read_gyro());
bench!(read_mag());

bench!(read_pressure());
bench!(read_temperature());

bench!(read_all());

// Benchmark Outputs
bench!(pwm_enable(false));
bench!(set_pwm_channel_value(PwmChannel::Ch1, 100));
bench!(set_pwm_freq_hz(60.0));
bench!(set_pwm_freq_prescale(100));

bench!(set_neopixel(&[[0, 0, 0]]));

bench!(set_led(UserLed::Led1, false));
bench!(set_led_toggle(UserLed::Led1));
bench!(get_led(UserLed::Led1));
}

criterion_group!(benches, navigator_benchmark);
criterion_main!(benches);

0 comments on commit 47c08c6

Please sign in to comment.