lofty-rs/benches/read_file.rs

50 lines
1.3 KiB
Rust
Raw Normal View History

2022-09-24 06:34:22 +00:00
use lofty::{ParseOptions, Probe};
2021-12-11 03:09:11 +00:00
use criterion::{criterion_group, criterion_main, Criterion};
use std::io::Cursor;
macro_rules! test_read_file {
2022-07-24 23:17:59 +00:00
($c:ident, [$(($NAME:ident, $path:expr)),+ $(,)?]) => {
2022-01-31 23:19:11 +00:00
let mut g = $c.benchmark_group("File reading (Inferred from Content)");
2021-12-11 03:09:11 +00:00
2022-01-31 23:19:11 +00:00
$(
const $NAME: &[u8] = include_bytes!($path);
2021-12-11 03:09:11 +00:00
2022-01-31 23:19:11 +00:00
g.bench_function(
stringify!($NAME),
|b| b.iter(|| {
Probe::new(Cursor::new($NAME))
2022-09-24 06:34:22 +00:00
.options(ParseOptions::new())
2022-01-31 23:19:11 +00:00
.guess_file_type()
.unwrap()
2022-09-24 06:34:22 +00:00
.read()
2022-01-31 23:19:11 +00:00
.unwrap()
})
);
)+
}
}
2021-12-11 03:09:11 +00:00
fn content_infer_read(c: &mut Criterion) {
2022-01-31 23:19:11 +00:00
test_read_file!(
c,
[
2022-10-14 13:06:27 +00:00
(AAC, "../tests/files/assets/minimal/full_test.aac"),
(AIFF, "../tests/files/assets/minimal/full_test.aiff"),
(APE, "../tests/files/assets/minimal/full_test.ape"),
(FLAC, "../tests/files/assets/minimal/full_test.flac"),
(MP4, "../tests/files/assets/minimal/m4a_codec_aac.m4a"),
(MP3, "../tests/files/assets/minimal/full_test.mp3"),
(OPUS, "../tests/files/assets/minimal/full_test.opus"),
(RIFF, "../tests/files/assets/minimal/wav_format_pcm.wav"),
(SPEEX, "../tests/files/assets/minimal/full_test.spx"),
2022-07-24 23:11:01 +00:00
(VORBIS, "../tests/files/assets/minimal/full_test.ogg"),
2022-07-24 23:17:59 +00:00
(WAVPACK, "../tests/files/assets/minimal/full_test.wv"),
2022-01-31 23:19:11 +00:00
]
);
}
2022-02-19 06:16:35 +00:00
criterion_group!(benches, content_infer_read);
criterion_main!(benches);