| 1 | use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion}; |
| 2 | |
| 3 | fn size_benchmarks(c: &mut Criterion) { |
| 4 | let mut group = c.benchmark_group("imagesize"); |
| 5 | |
| 6 | let mut paths = Vec::new(); |
| 7 | for file in walkdir::WalkDir::new("tests/images") |
| 8 | .into_iter() |
| 9 | .filter_map(|file| file.ok()) |
| 10 | { |
| 11 | if file.metadata().unwrap().is_file() { |
| 12 | paths.push(std::fs::canonicalize(file.path()).unwrap()); |
| 13 | } |
| 14 | } |
| 15 | |
| 16 | group.bench_with_input( |
| 17 | BenchmarkId::from_parameter(paths.len()), |
| 18 | &paths, |
| 19 | |b, paths| { |
| 20 | b.iter(|| { |
| 21 | for path in paths { |
| 22 | let _ = imagesize::size(black_box(path)); |
| 23 | } |
| 24 | }) |
| 25 | }, |
| 26 | ); |
| 27 | |
| 28 | group.finish(); |
| 29 | } |
| 30 | |
| 31 | criterion_group!(benches, size_benchmarks); |
| 32 | criterion_main!(benches); |