-
-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathcreate_tag.rs
126 lines (110 loc) · 3.12 KB
/
create_tag.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#![allow(missing_docs)]
use lofty::ape::ApeTag;
use lofty::config::WriteOptions;
use lofty::id3::v1::Id3v1Tag;
use lofty::id3::v2::{FrameId, Id3v2Tag};
use lofty::iff::aiff::AiffTextChunks;
use lofty::iff::wav::RiffInfoList;
use lofty::mp4::Ilst;
use lofty::ogg::VorbisComments;
use lofty::picture::{MimeType, Picture, PictureType};
use lofty::tag::{Accessor, TagExt};
use std::borrow::Cow;
use iai_callgrind::{library_benchmark, library_benchmark_group, main};
const ENCODER: &str = "Lavf57.56.101";
macro_rules! bench_tag_write {
([$(($NAME:ident, $tag:ty, |$tag_:ident| $extra_block:block)),+ $(,)?]) => {
$(
#[library_benchmark]
fn $NAME() {
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(1);
$tag_.set_genre(String::from("Electronic"));
$extra_block;
$tag_.dump_to(&mut v, WriteOptions::default()).unwrap();
}
)+
}
}
bench_tag_write!([
(aiff_text_chunks, AiffTextChunks, |tag| {}),
(apev2, ApeTag, |tag| {
use lofty::ape::ApeItem;
use lofty::tag::ItemValue;
let picture = Picture::new_unchecked(
PictureType::CoverFront,
Some(MimeType::Jpeg),
None,
include_bytes!("../benches_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::TextEncoding;
use lofty::id3::v2::{Frame, TextInformationFrame};
let picture = Picture::new_unchecked(
PictureType::CoverFront,
Some(MimeType::Jpeg),
None,
include_bytes!("../benches_assets/cover.jpg").to_vec(),
);
tag.insert_picture(picture);
tag.insert(Frame::Text(TextInformationFrame::new(
FrameId::Valid(Cow::Borrowed("TSSE")),
TextEncoding::Latin1,
String::from(ENCODER),
)));
}),
(id3v1, Id3v1Tag, |tag| {}),
(ilst, Ilst, |tag| {
use lofty::mp4::{Atom, AtomData, AtomIdent};
let picture = Picture::new_unchecked(
PictureType::CoverFront,
Some(MimeType::Jpeg),
None,
include_bytes!("../benches_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,
Some(MimeType::Jpeg),
None,
include_bytes!("../benches_assets/cover.jpg").to_vec(),
);
let _ = tag.insert_picture(picture, None).unwrap();
tag.push(String::from("ENCODER"), String::from(ENCODER));
}),
]);
library_benchmark_group!(
name = tag_writing;
benchmarks = aiff_text_chunks, apev2, id3v2, id3v1, ilst, riff_info, vorbis_comments
);
main!(library_benchmark_groups = tag_writing);