From a9610a576265f27cb6df4e6fabe6b9fa3651383f Mon Sep 17 00:00:00 2001 From: gered Date: Sun, 1 Jan 2023 12:43:15 -0500 Subject: [PATCH] add initial benchmark tests for asset loading only for gif bitmaps right now, since i want to (eventually) clean that up somewhat --- libretrogd/Cargo.toml | 4 ++++ libretrogd/benches/loading.rs | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 libretrogd/benches/loading.rs diff --git a/libretrogd/Cargo.toml b/libretrogd/Cargo.toml index 8ecc1ed..f6930fb 100644 --- a/libretrogd/Cargo.toml +++ b/libretrogd/Cargo.toml @@ -30,3 +30,7 @@ harness = false [[bench]] name = "blit" harness = false + +[[bench]] +name = "loading" +harness = false diff --git a/libretrogd/benches/loading.rs b/libretrogd/benches/loading.rs new file mode 100644 index 0000000..61812f7 --- /dev/null +++ b/libretrogd/benches/loading.rs @@ -0,0 +1,27 @@ +use std::io::Cursor; + +use criterion::{black_box, Criterion, criterion_group, criterion_main}; + +use libretrogd::graphics::*; + +pub static SMALL_GIF_FILE_BYTES: &[u8] = include_bytes!("../test-assets/test.gif"); +pub static LARGE_GIF_FILE_BYTES: &[u8] = include_bytes!("../test-assets/test_image.gif"); + +pub fn criterion_benchmark(c: &mut Criterion) { + c.bench_function("loading_small_gif", |b| { + b.iter(|| { + let mut reader = Cursor::new(SMALL_GIF_FILE_BYTES); + Bitmap::load_gif_bytes(black_box(&mut reader)).unwrap(); + }) + }); + + c.bench_function("loading_large_gif", |b| { + b.iter(|| { + let mut reader = Cursor::new(LARGE_GIF_FILE_BYTES); + Bitmap::load_gif_bytes(black_box(&mut reader)).unwrap(); + }) + }); +} + +criterion_group!(benches, criterion_benchmark); +criterion_main!(benches);