From e1be1b00e1dd3be1220d1471a19b228566c9edd2 Mon Sep 17 00:00:00 2001 From: Will Date: Tue, 19 Dec 2023 21:03:44 -0800 Subject: [PATCH] Support nostd benchmarks (#18) --- Cargo.toml | 2 +- benches/bench.rs | 23 ++++++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1e20d48..09e124e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ license = "MIT" name = "wmidi" readme = "README.md" repository = "https://github.com/RustAudio/wmidi" -version = "4.0.9" +version = "4.0.10" [lib] # Required to pass flags to criterion benchmark. diff --git a/benches/bench.rs b/benches/bench.rs index 0c64bdc..ffb3854 100644 --- a/benches/bench.rs +++ b/benches/bench.rs @@ -96,10 +96,6 @@ fn bench_from_bytes(c: &mut Criterion) { } fn bench_notes(c: &mut Criterion) { - let all_notes: Vec = (0..128) - .map(|n| wmidi::Note::try_from(n).unwrap()) - .collect(); - let all_notes = black_box(all_notes); c.bench_function("Note::try_from", |b| { b.iter(|| { let mut notes = [wmidi::Note::LOWEST_NOTE; 128]; @@ -120,6 +116,14 @@ fn bench_notes(c: &mut Criterion) { } }) }); +} + +#[cfg(feature = "std")] +fn bench_frequency(c: &mut Criterion) { + let all_notes: Vec = (0..128) + .map(|n| wmidi::Note::try_from(n).unwrap()) + .collect(); + let all_notes = black_box(all_notes); c.bench_function("Note::to_freq_f32", |b| { b.iter(|| { let mut freqs = [0f32; 128]; @@ -149,6 +153,15 @@ fn bench_notes(c: &mut Criterion) { }); } -criterion_group!(benchmarks, bench_to_slice, bench_from_bytes, bench_notes); +#[cfg(not(feature = "std"))] +fn bench_frequency(_: &mut Criterion) {} + +criterion_group!( + benchmarks, + bench_to_slice, + bench_from_bytes, + bench_notes, + bench_frequency +); criterion_main!(benchmarks);