aboutsummaryrefslogtreecommitdiff
path: root/vendor/gif/benches
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/gif/benches')
-rw-r--r--vendor/gif/benches/decode.rs81
-rw-r--r--vendor/gif/benches/rgb_frame.rs73
-rw-r--r--vendor/gif/benches/samples/test.gifbin0 -> 166028 bytes
-rw-r--r--vendor/gif/benches/samples/test.pngbin0 -> 429441 bytes
4 files changed, 154 insertions, 0 deletions
diff --git a/vendor/gif/benches/decode.rs b/vendor/gif/benches/decode.rs
new file mode 100644
index 0000000..8272cee
--- /dev/null
+++ b/vendor/gif/benches/decode.rs
@@ -0,0 +1,81 @@
+use criterion::{black_box, BenchmarkId, BenchmarkGroup, Criterion, Throughput, measurement::Measurement};
+use gif::Decoder;
+
+fn read_image(image: &[u8]) -> Option<Vec<u8>> {
+ let decoder = Decoder::new(black_box(image));
+ //decoder.set_param(gif::ColorOutput::RGBA);
+ let mut reader = decoder.unwrap();
+
+ while let Some(_) = reader.next_frame_info().unwrap() {
+ let mut v = vec![0; reader.buffer_size()];
+ reader.fill_buffer(&mut v).unwrap();
+ return Some(v);
+ }
+ None
+}
+
+fn read_metadata(image: &[u8]) {
+ let decoder = Decoder::new(black_box(image));
+ decoder.unwrap();
+}
+
+fn main() {
+ struct BenchDef {
+ data: &'static [u8],
+ id: &'static str,
+ sample_size: usize,
+ }
+
+ fn run_bench_def<M: Measurement>(group: &mut BenchmarkGroup<M>, def: BenchDef) {
+ group
+ .sample_size(def.sample_size)
+ .throughput(Throughput::Bytes(def.data.len() as u64))
+ .bench_with_input(
+ BenchmarkId::new(def.id, def.data.len()),
+ def.data,
+ |b, input| {
+ b.iter(|| read_image(input))
+ }
+ );
+ }
+
+ let mut c = Criterion::default().configure_from_args();
+ let mut group = c.benchmark_group("gif");
+
+ run_bench_def(&mut group, BenchDef {
+ data: include_bytes!("note.gif"),
+ id: "note.gif",
+ sample_size: 100,
+ });
+
+ run_bench_def(&mut group, BenchDef {
+ data: include_bytes!("photo.gif"),
+ id: "photo.gif",
+ sample_size: 20,
+ });
+
+ run_bench_def(&mut group, BenchDef {
+ data: include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/tests/samples/sample_1.gif")),
+ id: "sample_1.gif",
+ sample_size: 100,
+ });
+
+ run_bench_def(&mut group, BenchDef {
+ data: include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/tests/samples/sample_big.gif")),
+ id: "sample_big.gif",
+ sample_size: 20,
+ });
+
+ group
+ .bench_with_input(
+ "extract-metadata-note",
+ include_bytes!("note.gif"),
+ |b, input| {
+ b.iter(|| read_metadata(input))
+ }
+ );
+
+ group.finish();
+
+ c.final_summary();
+}
diff --git a/vendor/gif/benches/rgb_frame.rs b/vendor/gif/benches/rgb_frame.rs
new file mode 100644
index 0000000..a0d1934
--- /dev/null
+++ b/vendor/gif/benches/rgb_frame.rs
@@ -0,0 +1,73 @@
+use std::fs;
+
+use criterion::{Criterion, Throughput};
+use gif::{Encoder, Frame, Repeat};
+use png;
+
+const DIR: &str = "benches/samples";
+
+fn main()
+{
+ let mut c = Criterion::default().configure_from_args();
+ let mut group = c.benchmark_group("rgb_frame");
+
+ let dir = fs::read_dir(DIR).expect("Cant'r read dir:\n{}");
+
+ for path in dir {
+ let path = path.expect("Can't read path:\n{}").path();
+ if path.extension().unwrap() != "png" {
+ continue;
+ }
+
+ let mut reader = {
+ let input = fs::File::open(&path).unwrap();
+ let decoder = png::Decoder::new(input);
+ decoder.read_info().unwrap()
+ };
+
+ let mut buf = vec![0; reader.output_buffer_size()];
+ let info = reader.next_frame(&mut buf).unwrap();
+
+ let (w, h, size) = {
+ // could use try_into().unwrap() but probably no need
+ (info.width as u16, info.height as u16, info.buffer_size())
+ };
+
+ //size might have to be adjusted for large images
+ group
+ .sample_size(50)
+ .throughput(Throughput::Bytes(size as u64))
+ .bench_function(path.file_name().unwrap().to_str().unwrap(),
+ |b| {
+ match info.color_type {
+ png::ColorType::Rgb => b.iter(|| {
+ Frame::from_rgb_speed(w, h, &mut buf[..size], 30)
+ }),
+ png::ColorType::Rgba => b.iter(|| {
+ Frame::from_rgba_speed(w, h, &mut buf[..size], 30)
+ }),
+ c => {
+ println!("Image has wrong color type: {:?}", c);
+ }
+ }
+ });
+
+ // actually write the image as a singe frame gif... while MSE can be used
+ // for quality check, it might not be as good as visual inspection
+ let mut encoder = {
+ let output = fs::File::create(path.with_extension("gif")).unwrap();
+ Encoder::new(output, w, h, &[]).unwrap()
+ };
+ encoder.set_repeat(Repeat::Finite(0)).unwrap();
+
+ let frame = match info.color_type {
+ png::ColorType::Rgb => Frame::from_rgb(w, h, &mut buf[..size]),
+ png::ColorType::Rgba => Frame::from_rgba(w, h, &mut buf[..size]),
+ _ => continue,
+ };
+
+ encoder.write_frame(&frame).unwrap();
+ }
+ group.finish();
+ c.final_summary();
+}
diff --git a/vendor/gif/benches/samples/test.gif b/vendor/gif/benches/samples/test.gif
new file mode 100644
index 0000000..a2e032f
--- /dev/null
+++ b/vendor/gif/benches/samples/test.gif
Binary files differ
diff --git a/vendor/gif/benches/samples/test.png b/vendor/gif/benches/samples/test.png
new file mode 100644
index 0000000..ec11a5b
--- /dev/null
+++ b/vendor/gif/benches/samples/test.png
Binary files differ