|
1 | | -#[macro_use] |
2 | | -extern crate criterion; |
3 | | -extern crate mime_guess2; |
4 | | - |
5 | | -use self::criterion::Criterion; |
6 | | - |
7 | 1 | use mime_guess2::from_ext; |
8 | 2 |
|
9 | 3 | include!("../src/mime_types.rs"); |
10 | 4 |
|
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 | | - }); |
| 5 | +fn main() { |
| 6 | + // Run registered benchmarks. |
| 7 | + divan::main(); |
18 | 8 | } |
19 | 9 |
|
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 | | - }); |
| 10 | +/// Benchmark `from_ext` with standard extensions. |
| 11 | +#[divan::bench] |
| 12 | +fn from_ext_benchmark() { |
| 13 | + for (mime_ext, _) in MIME_TYPES { |
| 14 | + divan::black_box(from_ext(mime_ext).first_raw()); |
| 15 | + } |
28 | 16 | } |
29 | 17 |
|
30 | | -criterion_group!(benches, bench_mime_str, bench_mime_str_uppercase); |
31 | | -criterion_main!(benches); |
| 18 | +/// Benchmark `from_ext` with uppercased extensions. |
| 19 | +#[divan::bench] |
| 20 | +fn from_ext_uppercase_benchmark() { |
| 21 | + let uppercased: Vec<_> = MIME_TYPES.iter().map(|(s, _)| s.to_uppercase()).collect(); |
| 22 | + |
| 23 | + for mime_ext in uppercased { |
| 24 | + divan::black_box(from_ext(&mime_ext).first_raw()); |
| 25 | + } |
| 26 | +} |
0 commit comments