summaryrefslogtreecommitdiff
path: root/benches
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2023-09-04 22:40:18 -0400
committerpommicket <pommicket@gmail.com>2023-09-04 22:46:55 -0400
commit827122e165922c4010096c8d9ad32913ae06ab9e (patch)
treef1a6695c52bfdcfe2f1c6aac53a307aff061fcdc /benches
parent021e276598b44d31fc5b90ea145f3b80e97d6e22 (diff)
benchmark
Diffstat (limited to 'benches')
-rw-r--r--benches/bench.rs58
-rw-r--r--benches/large.pngbin0 -> 7655145 bytes
-rw-r--r--benches/small.pngbin0 -> 233 bytes
3 files changed, 58 insertions, 0 deletions
diff --git a/benches/bench.rs b/benches/bench.rs
new file mode 100644
index 0000000..a8c13ba
--- /dev/null
+++ b/benches/bench.rs
@@ -0,0 +1,58 @@
+use criterion::{criterion_group, criterion_main, Criterion};
+use std::hint::black_box;
+
+fn run_benches(c: &mut Criterion) {
+ let large_image = black_box(std::fs::read("benches/large.png").unwrap());
+ let small_image = black_box(std::fs::read("benches/small.png").unwrap());
+
+ let mut group = c.benchmark_group("large-image");
+ group.sample_size(50);
+
+ group.bench_function("tiny-png", |b| {
+ b.iter(|| {
+ let mut png = &large_image[..];
+ let header = tiny_png::read_png_header(&mut png).unwrap();
+ let mut buf = vec![0; header.required_bytes()];
+ let data = tiny_png::read_png(&mut png, Some(&header), &mut buf).unwrap();
+ std::hint::black_box(data);
+ })
+ });
+
+ group.bench_function("png", |b| {
+ b.iter(|| {
+ let png = &large_image[..];
+ let decoder = png::Decoder::new(png);
+ let mut reader = decoder.read_info().unwrap();
+ let mut png_buf = vec![0; reader.output_buffer_size()];
+ reader.next_frame(&mut png_buf).unwrap();
+ std::hint::black_box(png_buf);
+ })
+ });
+ group.finish();
+
+ let mut group = c.benchmark_group("small-image");
+ group.sample_size(1000);
+ group.bench_function("tiny-png", |b| {
+ b.iter(|| {
+ let mut png = &small_image[..];
+ let header = tiny_png::read_png_header(&mut png).unwrap();
+ let mut buf = vec![0; header.required_bytes()];
+ let data = tiny_png::read_png(&mut png, Some(&header), &mut buf).unwrap();
+ std::hint::black_box(data);
+ })
+ });
+ group.bench_function("png", |b| {
+ b.iter(|| {
+ let png = &small_image[..];
+ let decoder = png::Decoder::new(png);
+ let mut reader = decoder.read_info().unwrap();
+ let mut png_buf = vec![0; reader.output_buffer_size()];
+ reader.next_frame(&mut png_buf).unwrap();
+ std::hint::black_box(png_buf);
+ })
+ });
+ group.finish();
+}
+
+criterion_group!(benches, run_benches);
+criterion_main!(benches);
diff --git a/benches/large.png b/benches/large.png
new file mode 100644
index 0000000..f0344e5
--- /dev/null
+++ b/benches/large.png
Binary files differ
diff --git a/benches/small.png b/benches/small.png
new file mode 100644
index 0000000..47226a2
--- /dev/null
+++ b/benches/small.png
Binary files differ