Skip to content

Commit

Permalink
Benches: Add picture and encoder to create_tag benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
Serial-ATA committed Oct 23, 2023
1 parent af3b98d commit 66c63af
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 20 deletions.
Binary file added benches/assets/cover.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
118 changes: 98 additions & 20 deletions benches/create_tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,31 @@ use lofty::iff::aiff::AIFFTextChunks;
use lofty::iff::wav::RIFFInfoList;
use lofty::mp4::Ilst;
use lofty::ogg::VorbisComments;
use lofty::{Accessor, TagExt};
use lofty::{Accessor, MimeType, Picture, PictureType, TagExt};

use criterion::{criterion_group, criterion_main, Criterion};

const ENCODER: &str = "Lavf57.56.101";

macro_rules! bench_tag_write {
($c:ident, [$(($NAME:literal, $tag:ty)),+ $(,)?]) => {
($c:ident, [$(($NAME:literal, $tag:ty, |$tag_:ident| $extra_block:block)),+ $(,)?]) => {
let mut g = $c.benchmark_group("Tag writing");

$(
g.bench_function(
$NAME,
|b| b.iter(|| {
let mut v = Vec::new();
let mut tag = <$tag>::default();

tag.set_artist(String::from("Dave Eddy"));
tag.set_title(String::from("TempleOS Hymn Risen (Remix)"));
tag.set_album(String::from("Summer"));
tag.set_year(2017);
tag.set_track_number(1);
tag.set_genre(String::from("Electronic"));
// TODO: Front cover
// TODO: Encoder
tag.dump_to(&mut v).unwrap();
let mut $tag_ = <$tag>::default();

$tag_.set_artist(String::from("Dave Eddy"));
$tag_.set_title(String::from("TempleOS Hymn Risen (Remix)"));
$tag_.set_album(String::from("Summer"));
$tag_.set_year(2017);
$tag_.set_track(1);
$tag_.set_genre(String::from("Electronic"));
$extra_block
$tag_.dump_to(&mut v).unwrap();
})
);
)+
Expand All @@ -39,13 +40,90 @@ fn bench_write(c: &mut Criterion) {
bench_tag_write!(
c,
[
("AIFF Text Chunks", AIFFTextChunks),
("APEv2", ApeTag),
("ID3v2", Id3v2Tag),
("ID3v1", Id3v1Tag),
("MP4 Ilst", Ilst),
("RIFF INFO", RIFFInfoList),
("Vorbis Comments", VorbisComments),
("AIFF Text Chunks", AIFFTextChunks, |tag| {}),
("APEv2", ApeTag, |tag| {
use lofty::ape::ApeItem;
use lofty::ItemValue;

let picture = Picture::new_unchecked(
PictureType::CoverFront,
MimeType::Jpeg,
None,
include_bytes!("assets/cover.jpg").to_vec(),
);

tag.insert(
ApeItem::new(
String::from("Cover (Front)"),
ItemValue::Binary(picture.as_ape_bytes()),
)
.unwrap(),
);
tag.insert(
ApeItem::new(
String::from("Encoder"),
ItemValue::Text(String::from(ENCODER)),
)
.unwrap(),
);
}),
("ID3v2", Id3v2Tag, |tag| {
use lofty::id3::v2::{Frame, FrameFlags, TextInformationFrame};
use lofty::TextEncoding;

let picture = Picture::new_unchecked(
PictureType::CoverFront,
MimeType::Jpeg,
None,
include_bytes!("assets/cover.jpg").to_vec(),
);

tag.insert_picture(picture);
tag.insert(
Frame::new(
"TSSE",
TextInformationFrame {
encoding: TextEncoding::Latin1,
value: String::from(ENCODER),
},
FrameFlags::default(),
)
.unwrap(),
);
}),
("ID3v1", Id3v1Tag, |tag| {}),
("MP4 Ilst", Ilst, |tag| {
use lofty::mp4::{Atom, AtomData, AtomIdent};

let picture = Picture::new_unchecked(
PictureType::CoverFront,
MimeType::Jpeg,
None,
include_bytes!("assets/cover.jpg").to_vec(),
);

tag.insert_picture(picture);
tag.insert(Atom::new(
AtomIdent::Fourcc(*b"\xa9too"),
AtomData::UTF8(String::from(ENCODER)),
));
}),
("RIFF INFO", RIFFInfoList, |tag| {
tag.insert(String::from("ISFT"), String::from(ENCODER));
}),
("Vorbis Comments", VorbisComments, |tag| {
use lofty::ogg::OggPictureStorage;

let picture = Picture::new_unchecked(
PictureType::CoverFront,
MimeType::Jpeg,
None,
include_bytes!("assets/cover.jpg").to_vec(),
);

let _ = tag.insert_picture(picture, None).unwrap();
tag.push(String::from("ENCODER"), String::from(ENCODER));
}),
]
);
}
Expand Down

1 comment on commit 66c63af

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 66c63af Previous: 776c7da Ratio
Tag writing/APEv2 48655 ns/iter (± 1501) 659 ns/iter (± 2) 73.83
Tag writing/ID3v2 44652 ns/iter (± 205) 802 ns/iter (± 0) 55.68
Tag writing/MP4 Ilst 26175 ns/iter (± 466) 708 ns/iter (± 0) 36.97
Tag writing/RIFF INFO 1460 ns/iter (± 4) 458 ns/iter (± 6) 3.19
Tag writing/Vorbis Comments 223694 ns/iter (± 2594) 907 ns/iter (± 5) 246.63
File reading (Inferred from Content)/AAC 349757 ns/iter (± 8197) 3040 ns/iter (± 11) 115.05
File reading (Inferred from Content)/AIFF 31370 ns/iter (± 285) 1248 ns/iter (± 20) 25.14
File reading (Inferred from Content)/APE 17671 ns/iter (± 828) 1583 ns/iter (± 41) 11.16
File reading (Inferred from Content)/FLAC 29961 ns/iter (± 420) 891 ns/iter (± 1) 33.63
File reading (Inferred from Content)/MP4 34086 ns/iter (± 463) 2060 ns/iter (± 2) 16.55
File reading (Inferred from Content)/MP3 24151 ns/iter (± 204) 1559 ns/iter (± 14) 15.49
File reading (Inferred from Content)/MPC 341613 ns/iter (± 1892) 2143 ns/iter (± 31) 159.41
File reading (Inferred from Content)/OPUS 374381 ns/iter (± 2020) 1664 ns/iter (± 3) 224.99
File reading (Inferred from Content)/RIFF 35807 ns/iter (± 183) 1311 ns/iter (± 9) 27.31
File reading (Inferred from Content)/SPEEX 373997 ns/iter (± 530) 1837 ns/iter (± 3) 203.59
File reading (Inferred from Content)/VORBIS 438386 ns/iter (± 1001) 1962 ns/iter (± 6) 223.44
File reading (Inferred from Content)/WAVPACK 18672 ns/iter (± 888) 866 ns/iter (± 1) 21.56

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.