|
1 | 1 | #![allow(elided_lifetimes_in_paths)]
|
2 | 2 |
|
3 | 3 | mod toml_edit {
|
4 |
| - use super::{manifest, Data, MANIFESTS}; |
| 4 | + use toml_benchmarks::{manifest, Data, MANIFESTS}; |
5 | 5 |
|
6 | 6 | #[divan::bench(args=MANIFESTS)]
|
7 |
| - fn document(sample: &Data) -> ::toml_edit::DocumentMut { |
| 7 | + fn document(sample: &Data<'static>) -> ::toml_edit::DocumentMut { |
8 | 8 | sample.content().parse().unwrap()
|
9 | 9 | }
|
10 | 10 |
|
11 | 11 | #[divan::bench(args=MANIFESTS)]
|
12 |
| - fn manifest(sample: &Data) -> manifest::Manifest { |
| 12 | + fn manifest(sample: &Data<'static>) -> manifest::Manifest { |
13 | 13 | ::toml_edit::de::from_str(sample.content()).unwrap()
|
14 | 14 | }
|
15 | 15 | }
|
16 | 16 |
|
17 | 17 | mod toml {
|
18 |
| - use super::{manifest, Data, MANIFESTS}; |
| 18 | + use toml_benchmarks::{manifest, Data, MANIFESTS}; |
19 | 19 |
|
20 | 20 | #[divan::bench(args=MANIFESTS)]
|
21 |
| - fn document(sample: &Data) -> ::toml::Value { |
| 21 | + fn document(sample: &Data<'static>) -> ::toml::Value { |
22 | 22 | sample.content().parse().unwrap()
|
23 | 23 | }
|
24 | 24 |
|
25 | 25 | #[divan::bench(args=MANIFESTS)]
|
26 |
| - fn manifest(sample: &Data) -> manifest::Manifest { |
| 26 | + fn manifest(sample: &Data<'static>) -> manifest::Manifest { |
27 | 27 | ::toml::de::from_str(sample.content()).unwrap()
|
28 | 28 | }
|
29 | 29 | }
|
30 | 30 |
|
31 | 31 | mod toml_v05 {
|
32 |
| - use super::{manifest, Data, MANIFESTS}; |
| 32 | + use toml_benchmarks::{manifest, Data, MANIFESTS}; |
33 | 33 |
|
34 | 34 | #[divan::bench(args=MANIFESTS)]
|
35 |
| - fn document(sample: &Data) -> ::toml_old::Value { |
| 35 | + fn document(sample: &Data<'static>) -> ::toml_old::Value { |
36 | 36 | sample.content().parse().unwrap()
|
37 | 37 | }
|
38 | 38 |
|
39 | 39 | #[divan::bench(args=MANIFESTS)]
|
40 |
| - fn manifest(sample: &Data) -> manifest::Manifest { |
| 40 | + fn manifest(sample: &Data<'static>) -> manifest::Manifest { |
41 | 41 | ::toml_old::de::from_str(sample.content()).unwrap()
|
42 | 42 | }
|
43 | 43 | }
|
44 | 44 |
|
45 |
| -fn main() { |
46 |
| - divan::main(); |
47 |
| -} |
48 |
| - |
49 |
| -#[derive(Debug)] |
50 |
| -pub struct Data(&'static str, &'static str); |
51 |
| - |
52 |
| -impl Data { |
53 |
| - pub const fn name(&self) -> &'static str { |
54 |
| - self.0 |
55 |
| - } |
| 45 | +mod serde_json { |
| 46 | + use toml_benchmarks::{manifest, Data, MANIFESTS}; |
56 | 47 |
|
57 |
| - pub const fn content(&self) -> &'static str { |
58 |
| - self.1 |
| 48 | + #[divan::bench(args=MANIFESTS)] |
| 49 | + fn document(bencher: divan::Bencher, sample: &Data) { |
| 50 | + let value = toml_edit::de::from_str::<serde_json::Value>(sample.content()).unwrap(); |
| 51 | + let json = serde_json::to_string_pretty(&value).unwrap(); |
| 52 | + bencher |
| 53 | + .with_inputs(|| { |
| 54 | + let sample = Data(sample.name(), &json); |
| 55 | + sample |
| 56 | + }) |
| 57 | + .bench_values(|sample| { |
| 58 | + serde_json::from_str::<::toml::Value>(sample.content()).unwrap() |
| 59 | + }); |
59 | 60 | }
|
60 |
| -} |
61 | 61 |
|
62 |
| -impl std::fmt::Display for Data { |
63 |
| - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
64 |
| - self.name().fmt(f) |
| 62 | + #[divan::bench(args=MANIFESTS)] |
| 63 | + fn manifest(bencher: divan::Bencher, sample: &Data) { |
| 64 | + let value = toml_edit::de::from_str::<serde_json::Value>(sample.content()).unwrap(); |
| 65 | + let json = serde_json::to_string_pretty(&value).unwrap(); |
| 66 | + bencher |
| 67 | + .with_inputs(|| { |
| 68 | + let sample = Data(sample.name(), &json); |
| 69 | + sample |
| 70 | + }) |
| 71 | + .bench_values(|sample| { |
| 72 | + serde_json::from_str::<manifest::Manifest>(sample.content()).unwrap() |
| 73 | + }); |
65 | 74 | }
|
66 | 75 | }
|
67 | 76 |
|
68 |
| -const MANIFESTS: &[Data] = &[Data("0-minimal", MINIMAL), Data("1-medium", MEDIUM)]; |
69 |
| - |
70 |
| -const MINIMAL: &str = r#" |
71 |
| -[package] |
72 |
| -name = "bar" |
73 |
| -version = "0.1.0" |
74 |
| -edition = "2018" |
75 |
| -
|
76 |
| -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
77 |
| -
|
78 |
| -[dependencies] |
79 |
| -"#; |
80 |
| - |
81 |
| -const MEDIUM: &str = r#" |
82 |
| -[package] |
83 |
| -name = "cargo" |
84 |
| -version = "0.57.0" |
85 |
| -edition = "2018" |
86 |
| -authors = ["Yehuda Katz <[email protected]>", |
87 |
| - "Carl Lerche <[email protected]>", |
88 |
| - "Alex Crichton <[email protected]>"] |
89 |
| -license = "MIT OR Apache-2.0" |
90 |
| -homepage = "https://crates.io" |
91 |
| -repository = "https://github.com/rust-lang/cargo" |
92 |
| -documentation = "https://docs.rs/cargo" |
93 |
| -readme = "README.md" |
94 |
| -description = """ |
95 |
| -Cargo, a package manager for Rust. |
96 |
| -""" |
97 |
| -
|
98 |
| -[lib] |
99 |
| -name = "cargo" |
100 |
| -path = "src/cargo/lib.rs" |
101 |
| -
|
102 |
| -[dependencies] |
103 |
| -atty = "0.2" |
104 |
| -bytesize = "1.0" |
105 |
| -cargo-platform = { path = "crates/cargo-platform", version = "0.1.2" } |
106 |
| -cargo-util = { path = "crates/cargo-util", version = "0.1.1" } |
107 |
| -crates-io = { path = "crates/crates-io", version = "0.33.0" } |
108 |
| -crossbeam-utils = "0.8" |
109 |
| -curl = { version = "0.4.38", features = ["http2"] } |
110 |
| -curl-sys = "0.4.45" |
111 |
| -env_logger = "0.9.0" |
112 |
| -pretty_env_logger = { version = "0.4", optional = true } |
113 |
| -anyhow = "1.0" |
114 |
| -filetime = "0.2.9" |
115 |
| -flate2 = { version = "1.0.3", default-features = false, features = ["zlib"] } |
116 |
| -git2 = "0.13.16" |
117 |
| -git2-curl = "0.14.1" |
118 |
| -glob = "0.3.0" |
119 |
| -hex = "0.4" |
120 |
| -home = "0.5" |
121 |
| -humantime = "2.0.0" |
122 |
| -ignore = "0.4.7" |
123 |
| -lazy_static = "1.2.0" |
124 |
| -jobserver = "0.1.24" |
125 |
| -lazycell = "1.2.0" |
126 |
| -libc = "0.2" |
127 |
| -log = "0.4.6" |
128 |
| -libgit2-sys = "0.12.18" |
129 |
| -memchr = "2.1.3" |
130 |
| -num_cpus = "1.0" |
131 |
| -opener = "0.5" |
132 |
| -percent-encoding = "2.0" |
133 |
| -rustfix = "0.6.0" |
134 |
| -semver = { version = "1.0.3", features = ["serde"] } |
135 |
| -serde = { version = "1.0.123", features = ["derive"] } |
136 |
| -serde_ignored = "0.1.0" |
137 |
| -serde_json = { version = "1.0.30", features = ["raw_value"] } |
138 |
| -shell-escape = "0.1.4" |
139 |
| -strip-ansi-escapes = "0.1.0" |
140 |
| -tar = { version = "0.4.35", default-features = false } |
141 |
| -tempfile = "3.0" |
142 |
| -termcolor = "1.1" |
143 |
| -toml = "0.5.7" |
144 |
| -unicode-xid = "0.2.0" |
145 |
| -url = "2.2.2" |
146 |
| -walkdir = "2.2" |
147 |
| -clap = "2.31.2" |
148 |
| -unicode-width = "0.1.5" |
149 |
| -openssl = { version = '0.10.11', optional = true } |
150 |
| -im-rc = "15.0.0" |
151 |
| -itertools = "0.10.0" |
152 |
| -
|
153 |
| -# A noop dependency that changes in the Rust repository, it's a bit of a hack. |
154 |
| -# See the `src/tools/rustc-workspace-hack/README.md` file in `rust-lang/rust` |
155 |
| -# for more information. |
156 |
| -rustc-workspace-hack = "1.0.0" |
157 |
| -
|
158 |
| -[target.'cfg(windows)'.dependencies] |
159 |
| -fwdansi = "1.1.0" |
160 |
| -
|
161 |
| -[target.'cfg(windows)'.dependencies.winapi] |
162 |
| -version = "0.3" |
163 |
| -features = [ |
164 |
| - "basetsd", |
165 |
| - "handleapi", |
166 |
| - "jobapi", |
167 |
| - "jobapi2", |
168 |
| - "memoryapi", |
169 |
| - "minwindef", |
170 |
| - "ntdef", |
171 |
| - "ntstatus", |
172 |
| - "processenv", |
173 |
| - "processthreadsapi", |
174 |
| - "psapi", |
175 |
| - "synchapi", |
176 |
| - "winerror", |
177 |
| - "winbase", |
178 |
| - "wincon", |
179 |
| - "winnt", |
180 |
| -] |
181 |
| -
|
182 |
| -[dev-dependencies] |
183 |
| -cargo-test-macro = { path = "crates/cargo-test-macro" } |
184 |
| -cargo-test-support = { path = "crates/cargo-test-support" } |
185 |
| -
|
186 |
| -[build-dependencies] |
187 |
| -flate2 = { version = "1.0.3", default-features = false, features = ["zlib"] } |
188 |
| -tar = { version = "0.4.26", default-features = false } |
189 |
| -
|
190 |
| -[[bin]] |
191 |
| -name = "cargo" |
192 |
| -test = false |
193 |
| -doc = false |
194 |
| -
|
195 |
| -[features] |
196 |
| -deny-warnings = [] |
197 |
| -vendored-openssl = ["openssl/vendored"] |
198 |
| -pretty-env-logger = ["pretty_env_logger"] |
199 |
| -"#; |
200 |
| - |
201 |
| -mod manifest { |
202 |
| - use std::collections::HashMap; |
203 |
| - |
204 |
| - #[derive(Clone, Debug, serde::Serialize, serde::Deserialize)] |
205 |
| - #[serde(rename_all = "kebab-case")] |
206 |
| - pub(crate) struct Manifest { |
207 |
| - package: Package, |
208 |
| - #[serde(default)] |
209 |
| - lib: Option<Lib>, |
210 |
| - #[serde(default)] |
211 |
| - bin: Vec<Bin>, |
212 |
| - #[serde(default)] |
213 |
| - features: HashMap<String, Vec<String>>, |
214 |
| - #[serde(default)] |
215 |
| - dependencies: HashMap<String, Dependency>, |
216 |
| - #[serde(default)] |
217 |
| - build_dependencies: HashMap<String, Dependency>, |
218 |
| - #[serde(default)] |
219 |
| - dev_dependencies: HashMap<String, Dependency>, |
220 |
| - #[serde(default)] |
221 |
| - target: HashMap<String, Target>, |
222 |
| - } |
223 |
| - |
224 |
| - #[derive(Clone, Debug, serde::Serialize, serde::Deserialize)] |
225 |
| - #[serde(rename_all = "kebab-case")] |
226 |
| - pub(crate) struct Package { |
227 |
| - name: String, |
228 |
| - version: String, |
229 |
| - #[serde(default)] |
230 |
| - edition: Option<String>, |
231 |
| - #[serde(default)] |
232 |
| - authors: Vec<String>, |
233 |
| - #[serde(default)] |
234 |
| - license: Option<String>, |
235 |
| - #[serde(default)] |
236 |
| - homepage: Option<String>, |
237 |
| - #[serde(default)] |
238 |
| - repository: Option<String>, |
239 |
| - #[serde(default)] |
240 |
| - documentation: Option<String>, |
241 |
| - #[serde(default)] |
242 |
| - readme: Option<String>, |
243 |
| - #[serde(default)] |
244 |
| - description: Option<String>, |
245 |
| - } |
246 |
| - |
247 |
| - #[derive(Clone, Debug, serde::Serialize, serde::Deserialize)] |
248 |
| - #[serde(rename_all = "kebab-case")] |
249 |
| - pub(crate) struct Lib { |
250 |
| - name: String, |
251 |
| - #[serde(default)] |
252 |
| - path: Option<String>, |
253 |
| - } |
254 |
| - |
255 |
| - #[derive(Clone, Debug, serde::Serialize, serde::Deserialize)] |
256 |
| - #[serde(rename_all = "kebab-case")] |
257 |
| - pub(crate) struct Bin { |
258 |
| - name: String, |
259 |
| - #[serde(default)] |
260 |
| - test: bool, |
261 |
| - #[serde(default)] |
262 |
| - doc: bool, |
263 |
| - } |
264 |
| - |
265 |
| - #[derive(Clone, Debug, serde::Serialize, serde::Deserialize)] |
266 |
| - #[serde(rename_all = "kebab-case")] |
267 |
| - #[serde(untagged)] |
268 |
| - pub(crate) enum Dependency { |
269 |
| - Version(String), |
270 |
| - Full(DependencyFull), |
271 |
| - } |
272 |
| - |
273 |
| - #[derive(Clone, Debug, serde::Serialize, serde::Deserialize)] |
274 |
| - #[serde(rename_all = "kebab-case")] |
275 |
| - pub(crate) struct DependencyFull { |
276 |
| - #[serde(default)] |
277 |
| - version: Option<String>, |
278 |
| - #[serde(default)] |
279 |
| - path: Option<String>, |
280 |
| - #[serde(default)] |
281 |
| - default_features: bool, |
282 |
| - #[serde(default)] |
283 |
| - optional: bool, |
284 |
| - #[serde(default)] |
285 |
| - features: Vec<String>, |
286 |
| - } |
287 |
| - |
288 |
| - #[derive(Clone, Debug, serde::Serialize, serde::Deserialize)] |
289 |
| - #[serde(rename_all = "kebab-case")] |
290 |
| - pub(crate) struct Target { |
291 |
| - #[serde(default)] |
292 |
| - dependencies: HashMap<String, Dependency>, |
293 |
| - #[serde(default)] |
294 |
| - build_dependencies: HashMap<String, Dependency>, |
295 |
| - #[serde(default)] |
296 |
| - dev_dependencies: HashMap<String, Dependency>, |
297 |
| - } |
| 77 | +fn main() { |
| 78 | + divan::main(); |
298 | 79 | }
|
0 commit comments