diff --git a/benches/bench.rs b/benches/bench.rs new file mode 100644 index 0000000000..7318c8ac0c --- /dev/null +++ b/benches/bench.rs @@ -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);