add initial benchmark tests for asset loading

only for gif bitmaps right now, since i want to (eventually) clean that
up somewhat
This commit is contained in:
Gered 2023-01-01 12:43:15 -05:00
parent ed754cb9ac
commit a9610a5762
2 changed files with 31 additions and 0 deletions

View file

@ -30,3 +30,7 @@ harness = false
[[bench]]
name = "blit"
harness = false
[[bench]]
name = "loading"
harness = false

View file

@ -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);