Debian Codegraph @

third_party/rust/mime_guess/benches/benchmark.rs

raw
1 #[macro_use]
2 extern crate criterion;
3 extern crate mime_guess;
4
5 use self::criterion::Criterion;
6
7 use mime_guess::from_ext;
8
9 include!("../src/mime_types.rs");
10
11 /// WARNING: this may take a while!
12 fn bench_mime_str(c: &mut Criterion) {
13 c.bench_function("from_ext", |b| {
14 for (mime_ext, _) in MIME_TYPES {
15 b.iter(|| from_ext(mime_ext).first_raw());
16 }
17 });
18 }
19
20 fn bench_mime_str_uppercase(c: &mut Criterion) {
21 c.bench_function("from_ext uppercased", |b| {
22 let uppercased = MIME_TYPES.into_iter().map(|(s, _)| s.to_uppercase());
23
24 for mime_ext in uppercased {
25 b.iter(|| from_ext(&mime_ext).first_raw());
26 }
27 });
28 }
29
30 criterion_group!(benches, bench_mime_str, bench_mime_str_uppercase);
31 criterion_main!(benches);