summaryrefslogtreecommitdiff
path: root/vendor/png/benches/decoder.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2024-01-08 00:21:28 +0300
committerValentin Popov <valentin@popov.link>2024-01-08 00:21:28 +0300
commit1b6a04ca5504955c571d1c97504fb45ea0befee4 (patch)
tree7579f518b23313e8a9748a88ab6173d5e030b227 /vendor/png/benches/decoder.rs
parent5ecd8cf2cba827454317368b68571df0d13d7842 (diff)
downloadfparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.tar.xz
fparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.zip
Initial vendor packages
Signed-off-by: Valentin Popov <valentin@popov.link>
Diffstat (limited to 'vendor/png/benches/decoder.rs')
-rw-r--r--vendor/png/benches/decoder.rs38
1 files changed, 38 insertions, 0 deletions
diff --git a/vendor/png/benches/decoder.rs b/vendor/png/benches/decoder.rs
new file mode 100644
index 0000000..a078c9a
--- /dev/null
+++ b/vendor/png/benches/decoder.rs
@@ -0,0 +1,38 @@
+use std::fs;
+
+use criterion::{criterion_group, criterion_main, Criterion, Throughput};
+use png::Decoder;
+
+fn load_all(c: &mut Criterion) {
+ for entry in fs::read_dir("tests/benches/").unwrap().flatten() {
+ match entry.path().extension() {
+ Some(st) if st == "png" => {}
+ _ => continue,
+ }
+
+ let data = fs::read(entry.path()).unwrap();
+ bench_file(c, data, entry.file_name().into_string().unwrap());
+ }
+}
+
+criterion_group!(benches, load_all);
+criterion_main!(benches);
+
+fn bench_file(c: &mut Criterion, data: Vec<u8>, name: String) {
+ let mut group = c.benchmark_group("decode");
+ group.sample_size(20);
+
+ let decoder = Decoder::new(&*data);
+ let mut reader = decoder.read_info().unwrap();
+ let mut image = vec![0; reader.output_buffer_size()];
+ let info = reader.next_frame(&mut image).unwrap();
+
+ group.throughput(Throughput::Bytes(info.buffer_size() as u64));
+ group.bench_with_input(name, &data, |b, data| {
+ b.iter(|| {
+ let decoder = Decoder::new(data.as_slice());
+ let mut decoder = decoder.read_info().unwrap();
+ decoder.next_frame(&mut image).unwrap();
+ })
+ });
+}