2022-09-24 06:34:22 +00:00
|
|
|
use lofty::{ParseOptions, Probe};
|
2021-04-21 17:48:21 +00:00
|
|
|
|
2024-04-09 19:48:32 +00:00
|
|
|
use iai_callgrind::{library_benchmark, library_benchmark_group, main};
|
2021-12-11 03:09:11 +00:00
|
|
|
|
2024-04-09 19:48:32 +00:00
|
|
|
use std::hint::black_box;
|
2021-12-11 03:09:11 +00:00
|
|
|
use std::io::Cursor;
|
|
|
|
|
|
|
|
macro_rules! test_read_file {
|
2024-04-09 19:48:32 +00:00
|
|
|
([$(($NAME:ident, $path:expr)),+ $(,)?]) => {
|
2022-01-31 23:19:11 +00:00
|
|
|
$(
|
2024-04-09 19:48:32 +00:00
|
|
|
paste::paste! {
|
|
|
|
#[library_benchmark]
|
|
|
|
fn [<$NAME:lower>]() {
|
|
|
|
const $NAME: &[u8] = include_bytes!($path);
|
2021-12-11 03:09:11 +00:00
|
|
|
|
2024-04-09 19:48:32 +00:00
|
|
|
black_box(Probe::new(Cursor::new($NAME))
|
|
|
|
.options(ParseOptions::new())
|
|
|
|
.guess_file_type()
|
|
|
|
.unwrap()
|
|
|
|
.read()
|
|
|
|
.unwrap());
|
|
|
|
}
|
|
|
|
}
|
2022-01-31 23:19:11 +00:00
|
|
|
)+
|
|
|
|
}
|
|
|
|
}
|
2021-12-11 03:09:11 +00:00
|
|
|
|
2024-04-09 19:48:32 +00:00
|
|
|
test_read_file!([
|
|
|
|
(AAC, "../benches_assets/01 TempleOS Hymn Risen (Remix).aac"),
|
|
|
|
(
|
|
|
|
AIFF,
|
|
|
|
"../benches_assets/01 TempleOS Hymn Risen (Remix).aiff"
|
|
|
|
),
|
|
|
|
(APE, "../benches_assets/01 TempleOS Hymn Risen (Remix).ape"),
|
|
|
|
(
|
|
|
|
FLAC,
|
|
|
|
"../benches_assets/01 TempleOS Hymn Risen (Remix).flac"
|
|
|
|
),
|
|
|
|
(MP4, "../benches_assets/01 TempleOS Hymn Risen (Remix).m4a"),
|
|
|
|
(MP3, "../benches_assets/01 TempleOS Hymn Risen (Remix).mp3"),
|
|
|
|
(MPC, "../benches_assets/01 TempleOS Hymn Risen (Remix).mpc"),
|
|
|
|
(
|
|
|
|
OPUS,
|
|
|
|
"../benches_assets/01 TempleOS Hymn Risen (Remix).opus"
|
|
|
|
),
|
|
|
|
(RIFF, "../benches_assets/01 TempleOS Hymn Risen (Remix).wav"),
|
|
|
|
(
|
|
|
|
SPEEX,
|
|
|
|
"../benches_assets/01 TempleOS Hymn Risen (Remix).spx"
|
|
|
|
),
|
|
|
|
(
|
|
|
|
VORBIS,
|
|
|
|
"../benches_assets/01 TempleOS Hymn Risen (Remix).ogg"
|
|
|
|
),
|
|
|
|
(
|
|
|
|
WAVPACK,
|
|
|
|
"../benches_assets/01 TempleOS Hymn Risen (Remix).wv"
|
|
|
|
),
|
|
|
|
]);
|
2021-04-21 17:48:21 +00:00
|
|
|
|
2024-04-09 19:48:32 +00:00
|
|
|
library_benchmark_group!(
|
|
|
|
name = file_reading;
|
|
|
|
benchmarks = aac, aiff, ape, flac, mp4, mp3, mpc, opus, riff, speex, vorbis, wavpack
|
|
|
|
);
|
|
|
|
main!(library_benchmark_groups = file_reading);
|