From 4e6b4107cbea4c323c19280aa3736cd205746d32 Mon Sep 17 00:00:00 2001 From: Corwin Date: Fri, 6 Jan 2023 18:23:42 +0000 Subject: [PATCH 1/3] and test that benchmarks the allocator --- agb/src/agb_alloc/mod.rs | 41 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/agb/src/agb_alloc/mod.rs b/agb/src/agb_alloc/mod.rs index c18fbbb7..53e429b0 100644 --- a/agb/src/agb_alloc/mod.rs +++ b/agb/src/agb_alloc/mod.rs @@ -251,4 +251,45 @@ mod test { "address of allocation should be within iwram, instead at {p:?}" ); } + + #[test_case] + fn benchmark_allocation(_gba: &mut crate::Gba) { + let mut stored: Vec> = Vec::new(); + + let mut rng = crate::rng::RandomNumberGenerator::new(); + + const MAX_VEC_LENGTH: usize = 100; + + enum Action { + Add { size: usize }, + Remove { index: usize }, + } + + let next_action = |rng: &mut crate::rng::RandomNumberGenerator, stored: &[Vec]| { + if stored.len() >= MAX_VEC_LENGTH { + Action::Remove { + index: (rng.gen() as usize) % stored.len(), + } + } else if stored.is_empty() || rng.gen() as usize % 4 != 0 { + Action::Add { + size: rng.gen() as usize % 32, + } + } else { + Action::Remove { + index: (rng.gen() as usize) % stored.len(), + } + } + }; + + for _ in 0..10000 { + match next_action(&mut rng, &stored) { + Action::Add { size } => { + stored.push(Vec::with_capacity(size)); + } + Action::Remove { index } => { + stored.swap_remove(index); + } + } + } + } } From c78b4e62f24d1722be7187aa09e7c538a556247c Mon Sep 17 00:00:00 2001 From: Corwin Date: Fri, 6 Jan 2023 18:26:03 +0000 Subject: [PATCH 2/3] fix warnings in image converter --- agb-image-converter/src/lib.rs | 5 ++--- agb-image-converter/src/rust_generator.rs | 3 +-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/agb-image-converter/src/lib.rs b/agb-image-converter/src/lib.rs index a70b801c..656a9bcb 100644 --- a/agb-image-converter/src/lib.rs +++ b/agb-image-converter/src/lib.rs @@ -79,7 +79,7 @@ pub fn include_gfx(input: TokenStream) -> TokenStream { let mut palette256 = Palette256::new(); for (name, settings) in images.iter() { - let image_filename = &parent.join(&settings.filename()); + let image_filename = &parent.join(settings.filename()); let image = Image::load_from_file(image_filename); match settings.colours() { @@ -282,7 +282,7 @@ fn convert_image( optimisation_results: &Palette16OptimisationResults, assignment_offset: Option, ) -> proc_macro2::TokenStream { - let image_filename = &parent.join(&settings.filename()); + let image_filename = &parent.join(settings.filename()); let image = Image::load_from_file(image_filename); rust_generator::generate_code( @@ -339,7 +339,6 @@ fn palette_tile_data( .map(|colour| colour.to_rgb15()) .chain(iter::repeat(0)) .take(16) - .map(|colour| colour as u16) .collect() }) .collect(); diff --git a/agb-image-converter/src/rust_generator.rs b/agb-image-converter/src/rust_generator.rs index 374e6832..84b5632d 100644 --- a/agb-image-converter/src/rust_generator.rs +++ b/agb-image-converter/src/rust_generator.rs @@ -19,8 +19,7 @@ pub(crate) fn generate_palette_code( .into_iter() .map(|colour| colour.to_rgb15()) .chain(iter::repeat(0)) - .take(16) - .map(|colour| colour as u16); + .take(16); quote! { #crate_prefix::display::palette16::Palette16::new([ From e2580219c88cf6ed2134010cdabe09670d7eaac7 Mon Sep 17 00:00:00 2001 From: Corwin Date: Fri, 6 Jan 2023 18:27:02 +0000 Subject: [PATCH 3/3] fix warnings in tools --- tools/src/release.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/src/release.rs b/tools/src/release.rs index 8afa8a2d..dbe4bb9f 100644 --- a/tools/src/release.rs +++ b/tools/src/release.rs @@ -179,7 +179,7 @@ fn update_changelog(root_directory: &Path, new_version: &Version) -> Result