summaryrefslogtreecommitdiff
path: root/vendor/gif/benches/decode.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/gif/benches/decode.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/gif/benches/decode.rs')
-rw-r--r--vendor/gif/benches/decode.rs81
1 files changed, 81 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();
+}