mirror of
https://github.com/Serial-ATA/lofty-rs
synced 2024-11-10 06:34:18 +00:00
49 lines
1.3 KiB
Rust
49 lines
1.3 KiB
Rust
use lofty::{ParseOptions, Probe};
|
|
|
|
use criterion::{criterion_group, criterion_main, Criterion};
|
|
|
|
use std::io::Cursor;
|
|
|
|
macro_rules! test_read_file {
|
|
($c:ident, [$(($NAME:ident, $path:expr)),+ $(,)?]) => {
|
|
let mut g = $c.benchmark_group("File reading (Inferred from Content)");
|
|
|
|
$(
|
|
const $NAME: &[u8] = include_bytes!($path);
|
|
|
|
g.bench_function(
|
|
stringify!($NAME),
|
|
|b| b.iter(|| {
|
|
Probe::new(Cursor::new($NAME))
|
|
.options(ParseOptions::new())
|
|
.guess_file_type()
|
|
.unwrap()
|
|
.read()
|
|
.unwrap()
|
|
})
|
|
);
|
|
)+
|
|
}
|
|
}
|
|
|
|
fn content_infer_read(c: &mut Criterion) {
|
|
test_read_file!(
|
|
c,
|
|
[
|
|
(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"),
|
|
(VORBIS, "../tests/files/assets/minimal/full_test.ogg"),
|
|
(WAVPACK, "../tests/files/assets/minimal/full_test.wv"),
|
|
]
|
|
);
|
|
}
|
|
|
|
criterion_group!(benches, content_infer_read);
|
|
criterion_main!(benches);
|