-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a benchmark covering
Reader.next_frame_info
.
- Loading branch information
1 parent
a31e67a
commit 2a619fe
Showing
2 changed files
with
52 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<WallTime>, | ||
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, | ||
); | ||
}) | ||
}); | ||
} |