File: parse_benchmark.rs

package info (click to toggle)
rust-imagesize 0.13.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 224 kB
  • sloc: makefile: 5
file content (32 lines) | stat: -rw-r--r-- 878 bytes parent folder | download
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
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion};

fn size_benchmarks(c: &mut Criterion) {
    let mut group = c.benchmark_group("imagesize");

    let mut paths = Vec::new();
    for file in walkdir::WalkDir::new("tests/images")
        .into_iter()
        .filter_map(|file| file.ok())
    {
        if file.metadata().unwrap().is_file() {
            paths.push(std::fs::canonicalize(file.path()).unwrap());
        }
    }

    group.bench_with_input(
        BenchmarkId::from_parameter(paths.len()),
        &paths,
        |b, paths| {
            b.iter(|| {
                for path in paths {
                    let _ = imagesize::size(black_box(path));
                }
            })
        },
    );

    group.finish();
}

criterion_group!(benches, size_benchmarks);
criterion_main!(benches);