diff --git a/Cargo.toml b/Cargo.toml index 49d47ad5..6cd7ca2f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,13 +48,18 @@ name = "decoder" harness = false [[bench]] -path = "benches/unfilter.rs" -name = "unfilter" +path = "benches/expand_paletted.rs" +name = "expand_paletted" harness = false required-features = ["benchmarks"] [[bench]] -path = "benches/expand_paletted.rs" -name = "expand_paletted" +path = "benches/next_frame_info.rs" +name = "next_frame_info" +harness = false + +[[bench]] +path = "benches/unfilter.rs" +name = "unfilter" harness = false required-features = ["benchmarks"] diff --git a/benches/next_frame_info.rs b/benches/next_frame_info.rs new file mode 100644 index 00000000..1fa61c7b --- /dev/null +++ b/benches/next_frame_info.rs @@ -0,0 +1,43 @@ +use std::fs; +use std::path::Path; + +use criterion::{ + criterion_group, criterion_main, measurement::WallTime, BenchmarkGroup, Criterion, +}; +use png::Decoder; + +criterion_group! {benches, load_all} +criterion_main!(benches); + +fn load_all(c: &mut Criterion) { + let mut g = c.benchmark_group("next_frame_info"); + bench_file(&mut g, Path::new("tests/animated/basic_f20.png"), 18, 35); +} + +fn bench_file( + g: &mut BenchmarkGroup, + png_path: &Path, + number_of_frames_to_skip: usize, + expected_fctl_sequence_number: u32, +) { + let data = fs::read(png_path).unwrap(); + let name = format!("{}: {} skips", png_path.display(), number_of_frames_to_skip); + g.bench_with_input(&name, data.as_slice(), |b, data| { + b.iter(|| { + let decoder = Decoder::new(data); + let mut reader = decoder.read_info().unwrap(); + for _ in 0..number_of_frames_to_skip { + reader.next_frame_info().unwrap(); + } + assert_eq!( + reader + .info() + .frame_control + .as_ref() + .unwrap() + .sequence_number, + expected_fctl_sequence_number, + ); + }) + }); +}