Benches: Cleanup read_file bench

This commit is contained in:
Serial 2022-07-24 19:17:59 -04:00
parent f46153c825
commit da45e83967
No known key found for this signature in database
GPG key ID: DA95198DC17C4568
2 changed files with 31 additions and 28 deletions

View file

@ -9,36 +9,39 @@ use lofty::{Accessor, TagExt};
use criterion::{criterion_group, criterion_main, Criterion};
macro_rules! bench_tag_write {
($function:ident, $tag:ty) => {
fn $function() {
let mut v = Vec::new();
let mut tag = <$tag>::default();
($c:ident, [$(($NAME:literal, $tag:ty)),+ $(,)?]) => {
let mut g = $c.benchmark_group("Tag writing");
tag.set_artist(String::from("Foo artist"));
tag.set_title(String::from("Bar title"));
tag.set_album(String::from("Baz album"));
tag.dump_to(&mut v).unwrap();
}
};
$(
g.bench_function(
$NAME,
|b| b.iter(|| {
let mut v = Vec::new();
let mut tag = <$tag>::default();
tag.set_artist(String::from("Foo artist"));
tag.set_title(String::from("Bar title"));
tag.set_album(String::from("Baz album"));
tag.dump_to(&mut v).unwrap();
})
);
)+
}
}
bench_tag_write!(aiff_text, AIFFTextChunks);
bench_tag_write!(ape, ApeTag);
bench_tag_write!(id3v2, ID3v2Tag);
bench_tag_write!(id3v1, ID3v1Tag);
bench_tag_write!(ilst, Ilst);
bench_tag_write!(riff_info, RIFFInfoList);
bench_tag_write!(vorbis_comments, VorbisComments);
fn bench_write(c: &mut Criterion) {
let mut g = c.benchmark_group("Tag writing");
g.bench_function("AIFF Text Chunks", |b| b.iter(aiff_text));
g.bench_function("APEv2", |b| b.iter(ape));
g.bench_function("ID3v2", |b| b.iter(id3v2));
g.bench_function("ID3v1", |b| b.iter(id3v1));
g.bench_function("MP4 Ilst", |b| b.iter(ilst));
g.bench_function("RIFF INFO", |b| b.iter(riff_info));
g.bench_function("Vorbis Comments", |b| b.iter(vorbis_comments));
bench_tag_write!(
c,
[
("AIFF Text Chunks", AIFFTextChunks),
("APEv2", ApeTag),
("ID3v2", ID3v2Tag),
("ID3v1", ID3v1Tag),
("MP4 Ilst", Ilst),
("RIFF INFO", RIFFInfoList),
("Vorbis Comments", VorbisComments),
]
);
}
criterion_group!(benches, bench_write);

View file

@ -5,7 +5,7 @@ use criterion::{criterion_group, criterion_main, Criterion};
use std::io::Cursor;
macro_rules! test_read_file {
($c:ident, [$(($NAME:ident, $path:expr)),+]) => {
($c:ident, [$(($NAME:ident, $path:expr)),+ $(,)?]) => {
let mut g = $c.benchmark_group("File reading (Inferred from Content)");
$(
@ -38,7 +38,7 @@ fn content_infer_read(c: &mut Criterion) {
(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")
(WAVPACK, "../tests/files/assets/minimal/full_test.wv"),
]
);
}