Skip to content

Commit

Permalink
Support nostd benchmarks (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
wmedrano committed Dec 20, 2023
1 parent eaa5f4c commit e1be1b0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
23 changes: 18 additions & 5 deletions benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,6 @@ fn bench_from_bytes(c: &mut Criterion) {
}

fn bench_notes(c: &mut Criterion) {
let all_notes: Vec<wmidi::Note> = (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];
Expand All @@ -120,6 +116,14 @@ fn bench_notes(c: &mut Criterion) {
}
})
});
}

#[cfg(feature = "std")]
fn bench_frequency(c: &mut Criterion) {
let all_notes: Vec<wmidi::Note> = (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];
Expand Down Expand Up @@ -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);

0 comments on commit e1be1b0

Please sign in to comment.