mirror of
https://github.com/Serial-ATA/lofty-rs
synced 2025-03-04 14:57:17 +00:00
Fix benches
This commit is contained in:
parent
ca0ee7d6b8
commit
6fa5ee0890
2 changed files with 60 additions and 24 deletions
|
@ -14,8 +14,6 @@ categories = ["accessibility", "multimedia::audio"]
|
|||
flate2 = { version = "1.0.21", optional = true }
|
||||
# Ogg
|
||||
ogg_pager = "0.1.7"
|
||||
# Mp4
|
||||
simdutf8 = { version = "0.1.3", optional = true }
|
||||
|
||||
paste = "1.0.5"
|
||||
base64 = "0.13.0"
|
||||
|
@ -23,7 +21,7 @@ byteorder = "1.4.3"
|
|||
|
||||
[features]
|
||||
default = ["mp4_ilst", "vorbis_comments", "ape", "id3v1", "id3v2", "aiff_text_chunks", "riff_info_list"]
|
||||
mp4_ilst = ["simdutf8"]
|
||||
mp4_ilst = []
|
||||
vorbis_comments = []
|
||||
ape = []
|
||||
id3v1 = []
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
use criterion::{criterion_group, criterion_main, Criterion};
|
||||
use lofty::Probe;
|
||||
|
||||
macro_rules! test_read {
|
||||
use criterion::{criterion_group, criterion_main, Criterion};
|
||||
|
||||
use std::io::Cursor;
|
||||
|
||||
macro_rules! test_read_path {
|
||||
($function:ident, $path:expr) => {
|
||||
fn $function() {
|
||||
Probe::open($path).unwrap().read().unwrap();
|
||||
|
@ -9,26 +12,61 @@ macro_rules! test_read {
|
|||
};
|
||||
}
|
||||
|
||||
test_read!(read_aiff, "tests/files/assets/a_text.aiff");
|
||||
test_read!(read_ape, "tests/files/assets/a.ape");
|
||||
test_read!(read_flac, "tests/files/assets/a.flac");
|
||||
test_read!(read_m4a, "tests/files/assets/a.m4a");
|
||||
test_read!(read_mp3, "tests/files/assets/a.mp3");
|
||||
test_read!(read_vorbis, "tests/files/assets/a.ogg");
|
||||
test_read!(read_opus, "tests/files/assets/a.opus");
|
||||
test_read!(read_riff, "tests/files/assets/a.wav");
|
||||
test_read_path!(read_aiff_path, "tests/files/assets/a.aiff");
|
||||
test_read_path!(read_ape_path, "tests/files/assets/a.ape");
|
||||
test_read_path!(read_flac_path, "tests/files/assets/a.flac");
|
||||
test_read_path!(read_m4a_path, "tests/files/assets/a.m4a");
|
||||
test_read_path!(read_mp3_path, "tests/files/assets/a.mp3");
|
||||
test_read_path!(read_vorbis_path, "tests/files/assets/a.ogg");
|
||||
test_read_path!(read_opus_path, "tests/files/assets/a.opus");
|
||||
test_read_path!(read_riff_path, "tests/files/assets/a.wav");
|
||||
|
||||
fn bench_sig(c: &mut Criterion) {
|
||||
let mut g = c.benchmark_group("File reading");
|
||||
g.bench_function("AIFF", |b| b.iter(read_aiff));
|
||||
g.bench_function("APE", |b| b.iter(read_ape));
|
||||
g.bench_function("FLAC", |b| b.iter(read_flac));
|
||||
g.bench_function("MP4", |b| b.iter(read_m4a));
|
||||
g.bench_function("MP3", |b| b.iter(read_mp3));
|
||||
g.bench_function("VORBIS", |b| b.iter(read_vorbis));
|
||||
g.bench_function("OPUS", |b| b.iter(read_opus));
|
||||
g.bench_function("RIFF", |b| b.iter(read_riff));
|
||||
fn path_infer_read(c: &mut Criterion) {
|
||||
let mut g = c.benchmark_group("File reading (Inferred from Path)");
|
||||
g.bench_function("AIFF", |b| b.iter(read_aiff_path));
|
||||
g.bench_function("APE", |b| b.iter(read_ape_path));
|
||||
g.bench_function("FLAC", |b| b.iter(read_flac_path));
|
||||
g.bench_function("MP4", |b| b.iter(read_m4a_path));
|
||||
g.bench_function("MP3", |b| b.iter(read_mp3_path));
|
||||
g.bench_function("VORBIS", |b| b.iter(read_vorbis_path));
|
||||
g.bench_function("OPUS", |b| b.iter(read_opus_path));
|
||||
g.bench_function("RIFF", |b| b.iter(read_riff_path));
|
||||
}
|
||||
|
||||
criterion_group!(benches, bench_sig);
|
||||
macro_rules! test_read_file {
|
||||
($function:ident, $name:ident, $path:expr) => {
|
||||
const $name: &[u8] = include_bytes!($path);
|
||||
|
||||
fn $function() {
|
||||
Probe::new(Cursor::new($name))
|
||||
.guess_file_type()
|
||||
.unwrap()
|
||||
.read()
|
||||
.unwrap();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
test_read_file!(read_aiff_file, AIFF, "../tests/files/assets/a.aiff");
|
||||
test_read_file!(read_ape_file, APE, "../tests/files/assets/a.ape");
|
||||
test_read_file!(read_flac_file, FLAC, "../tests/files/assets/a.flac");
|
||||
test_read_file!(read_m4a_file, MP4, "../tests/files/assets/a.m4a");
|
||||
test_read_file!(read_mp3_file, MP3, "../tests/files/assets/a.mp3");
|
||||
test_read_file!(read_vorbis_file, VORBIS, "../tests/files/assets/a.ogg");
|
||||
test_read_file!(read_opus_file, OPUS, "../tests/files/assets/a.opus");
|
||||
test_read_file!(read_riff_file, RIFF, "../tests/files/assets/a.wav");
|
||||
|
||||
fn content_infer_read(c: &mut Criterion) {
|
||||
let mut g = c.benchmark_group("File reading (Inferred from Content)");
|
||||
g.bench_function("AIFF", |b| b.iter(read_aiff_file));
|
||||
g.bench_function("APE", |b| b.iter(read_ape_file));
|
||||
g.bench_function("FLAC", |b| b.iter(read_flac_file));
|
||||
g.bench_function("MP4", |b| b.iter(read_m4a_file));
|
||||
g.bench_function("MP3", |b| b.iter(read_mp3_file));
|
||||
g.bench_function("VORBIS", |b| b.iter(read_vorbis_file));
|
||||
g.bench_function("OPUS", |b| b.iter(read_opus_file));
|
||||
g.bench_function("RIFF", |b| b.iter(read_riff_file));
|
||||
}
|
||||
|
||||
criterion_group!(benches, path_infer_read, content_infer_read);
|
||||
criterion_main!(benches);
|
||||
|
|
Loading…
Add table
Reference in a new issue