mirror of
https://github.com/Serial-ATA/lofty-rs
synced 2025-03-04 14:57:17 +00:00
Add some benchmarks for reading from extension/signature
This commit is contained in:
parent
4d65545940
commit
90161287ab
5 changed files with 79 additions and 2 deletions
13
Cargo.toml
13
Cargo.toml
|
@ -41,4 +41,15 @@ mp3 = ["id3"]
|
|||
wav = ["riff"]
|
||||
vorbis = ["lewton", "metaflac", "opus_headers", "ogg"]
|
||||
all_tags = ["vorbis", "mp4", "mp3", "wav", "ape"]
|
||||
duration = ["mp3-duration"]
|
||||
duration = ["mp3-duration"]
|
||||
|
||||
[dev-dependencies]
|
||||
criterion = "0.3"
|
||||
|
||||
[[bench]]
|
||||
name = "read_from_extension"
|
||||
harness = false
|
||||
|
||||
[[bench]]
|
||||
name = "read_from_signature"
|
||||
harness = false
|
33
benches/read_from_extension.rs
Normal file
33
benches/read_from_extension.rs
Normal file
|
@ -0,0 +1,33 @@
|
|||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||
use lofty::{DetermineFrom, Tag};
|
||||
|
||||
macro_rules! test_read {
|
||||
($function:ident, $path:expr) => {
|
||||
fn $function() {
|
||||
let _ = Tag::new()
|
||||
.read_from_path($path, DetermineFrom::Extension)
|
||||
.unwrap();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
test_read!(read_ape, "tests/assets/a.ape");
|
||||
test_read!(read_flac, "tests/assets/a.flac");
|
||||
test_read!(read_m4a, "tests/assets/a.m4a");
|
||||
test_read!(read_mp3, "tests/assets/a.mp3");
|
||||
test_read!(read_ogg, "tests/assets/a.ogg");
|
||||
test_read!(read_opus, "tests/assets/a.opus");
|
||||
test_read!(read_wav, "tests/assets/a-id3.wav");
|
||||
|
||||
fn bench_ext(c: &mut Criterion) {
|
||||
c.bench_function("APE - Extension", |b| b.iter(|| read_ape()));
|
||||
c.bench_function("FLAC - Extension", |b| b.iter(|| read_flac()));
|
||||
c.bench_function("MP4 - Extension", |b| b.iter(|| read_m4a()));
|
||||
c.bench_function("MP3 - Extension", |b| b.iter(|| read_mp3()));
|
||||
c.bench_function("OGG - Extension", |b| b.iter(|| read_ogg()));
|
||||
c.bench_function("OPUS - Extension", |b| b.iter(|| read_opus()));
|
||||
c.bench_function("WAV - Extension", |b| b.iter(|| read_wav()));
|
||||
}
|
||||
|
||||
criterion_group!(benches, bench_ext);
|
||||
criterion_main!(benches);
|
33
benches/read_from_signature.rs
Normal file
33
benches/read_from_signature.rs
Normal file
|
@ -0,0 +1,33 @@
|
|||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||
use lofty::{DetermineFrom, Tag};
|
||||
|
||||
macro_rules! test_read {
|
||||
($function:ident, $path:expr) => {
|
||||
fn $function() {
|
||||
let _ = Tag::new()
|
||||
.read_from_path($path, DetermineFrom::Signature)
|
||||
.unwrap();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
test_read!(read_ape, "tests/assets/a.ape");
|
||||
test_read!(read_flac, "tests/assets/a.flac");
|
||||
test_read!(read_m4a, "tests/assets/a.m4a");
|
||||
test_read!(read_mp3, "tests/assets/a.mp3");
|
||||
test_read!(read_ogg, "tests/assets/a.ogg");
|
||||
test_read!(read_opus, "tests/assets/a.opus");
|
||||
test_read!(read_wav, "tests/assets/a.wav");
|
||||
|
||||
fn bench_sig(c: &mut Criterion) {
|
||||
c.bench_function("APE - Signature", |b| b.iter(|| read_ape()));
|
||||
c.bench_function("FLAC - Signature", |b| b.iter(|| read_flac()));
|
||||
c.bench_function("MP4 - Signature", |b| b.iter(|| read_m4a()));
|
||||
c.bench_function("MP3 - Signature", |b| b.iter(|| read_mp3()));
|
||||
c.bench_function("OGG - Signature", |b| b.iter(|| read_ogg()));
|
||||
c.bench_function("OPUS - Signature", |b| b.iter(|| read_opus()));
|
||||
c.bench_function("WAV - Signature", |b| b.iter(|| read_wav()));
|
||||
}
|
||||
|
||||
criterion_group!(benches, bench_sig);
|
||||
criterion_main!(benches);
|
|
@ -152,7 +152,7 @@ impl TagType {
|
|||
#[cfg(feature = "mp4")]
|
||||
"m4a" | "m4b" | "m4p" | "m4v" | "isom" | "mp4" => Ok(Self::Mp4),
|
||||
#[cfg(feature = "wav")]
|
||||
"wav" | "wave" => Ok(Self::Id3v2),
|
||||
"wav" | "wave" => Ok(Self::Riff(RiffFormat::ID3)),
|
||||
_ => Err(Error::UnsupportedFormat(ext.to_owned())),
|
||||
}
|
||||
}
|
||||
|
|
BIN
tests/assets/a-id3.wav
Normal file
BIN
tests/assets/a-id3.wav
Normal file
Binary file not shown.
Loading…
Add table
Reference in a new issue