Add a benchmark for landgen transitional_engine
authorunC0Rr
Thu, 19 Dec 2024 12:43:38 +0100
branchtransitional_engine
changeset 16051 a5eaeefa4ab3
parent 16050 624b74443b53
child 16052 6633961698ad
Add a benchmark for landgen
rust/landgen/Cargo.toml
rust/landgen/benches/benchmark.rs
--- 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
--- /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<Item = u32> {
+            (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(&parameters), &mut prng())
+    }));
+}
+
+criterion_group!(benches, generate_outline);
+criterion_main!(benches);