# HG changeset patch # User unC0Rr # Date 1734608618 -3600 # Node ID a5eaeefa4ab3c0c1141903a86b55fecb137cc70b # Parent 624b74443b53ffe8da5238ac8acd9a1bdd47d1bf Add a benchmark for landgen diff -r 624b74443b53 -r a5eaeefa4ab3 rust/landgen/Cargo.toml --- a/rust/landgen/Cargo.toml Thu Dec 19 12:40:48 2024 +0100 +++ b/rust/landgen/Cargo.toml Thu Dec 19 12:43:38 2024 +0100 @@ -8,5 +8,12 @@ integral-geometry = { path = "../integral-geometry" } land2d = { path = "../land2d" } vec2d = { path = "../vec2d" } -itertools = "0.7.8" +itertools = "0.13" png = "0.17" + +[dev-dependencies] +criterion = "0.5" + +[[bench]] +name = "benchmark" +harness = false diff -r 624b74443b53 -r a5eaeefa4ab3 rust/landgen/benches/benchmark.rs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rust/landgen/benches/benchmark.rs Thu Dec 19 12:43:38 2024 +0100 @@ -0,0 +1,58 @@ +use criterion::{black_box, criterion_group, criterion_main, Criterion}; +use integral_geometry::{Point, Rect, Size}; +use landgen; +use landgen::{LandGenerationParameters, LandGenerator}; +use landgen::outline_template_based::outline_template::OutlineTemplate; +use landgen::outline_template_based::template_based::TemplatedLandGenerator; + +pub fn generate_outline(c: &mut Criterion) { + let template = OutlineTemplate { + islands: vec![ + vec![ + Rect::from_box(273, 273, 2048, 2048), + Rect::from_box(683, 683, 32, 63), + Rect::from_box(1092, 1092, 2048, 2048), + ], + vec![ + Rect::from_box(1638, 1638, 2048, 2048), + Rect::from_box(2048, 2048, 32, 63), + Rect::from_box(2458, 2458, 2048, 2048), + ], + vec![ + Rect::from_box(3004, 3004, 2048, 2048), + Rect::from_box(3413, 3413, 32, 63), + Rect::from_box(3823, 3823, 2048, 2048), + ], + ], + walls: vec![], + fill_points: vec![Point::new(1, 0)], + size: Size { + width: 4096, + height: 2048, + }, + can_flip: false, + can_invert: false, + can_mirror: false, + is_negative: false, +}; + + let parameters = LandGenerationParameters::new( + 0u16, + 32768u16, + 10, + false, + false + ); + + c.bench_function("outline_generation", |b| b.iter(|| { + fn prng() -> impl Iterator { + (0..).map(|i| (i as u64 * 31_234_773 % 2_017_234_567) as u32) + } + + let gen = TemplatedLandGenerator::new(black_box(template.clone())); + gen.generate_land(black_box(¶meters), &mut prng()) + })); +} + +criterion_group!(benches, generate_outline); +criterion_main!(benches);