Skip to content

Commit e1be1b0

Browse files
authored
Support nostd benchmarks (#18)
1 parent eaa5f4c commit e1be1b0

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ license = "MIT"
77
name = "wmidi"
88
readme = "README.md"
99
repository = "https://github.com/RustAudio/wmidi"
10-
version = "4.0.9"
10+
version = "4.0.10"
1111

1212
[lib]
1313
# Required to pass flags to criterion benchmark.

benches/bench.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,6 @@ fn bench_from_bytes(c: &mut Criterion) {
9696
}
9797

9898
fn bench_notes(c: &mut Criterion) {
99-
let all_notes: Vec<wmidi::Note> = (0..128)
100-
.map(|n| wmidi::Note::try_from(n).unwrap())
101-
.collect();
102-
let all_notes = black_box(all_notes);
10399
c.bench_function("Note::try_from", |b| {
104100
b.iter(|| {
105101
let mut notes = [wmidi::Note::LOWEST_NOTE; 128];
@@ -120,6 +116,14 @@ fn bench_notes(c: &mut Criterion) {
120116
}
121117
})
122118
});
119+
}
120+
121+
#[cfg(feature = "std")]
122+
fn bench_frequency(c: &mut Criterion) {
123+
let all_notes: Vec<wmidi::Note> = (0..128)
124+
.map(|n| wmidi::Note::try_from(n).unwrap())
125+
.collect();
126+
let all_notes = black_box(all_notes);
123127
c.bench_function("Note::to_freq_f32", |b| {
124128
b.iter(|| {
125129
let mut freqs = [0f32; 128];
@@ -149,6 +153,15 @@ fn bench_notes(c: &mut Criterion) {
149153
});
150154
}
151155

152-
criterion_group!(benchmarks, bench_to_slice, bench_from_bytes, bench_notes);
156+
#[cfg(not(feature = "std"))]
157+
fn bench_frequency(_: &mut Criterion) {}
158+
159+
criterion_group!(
160+
benchmarks,
161+
bench_to_slice,
162+
bench_from_bytes,
163+
bench_notes,
164+
bench_frequency
165+
);
153166

154167
criterion_main!(benchmarks);

0 commit comments

Comments
 (0)