rust/landgen/benches/benchmark.rs
author unC0Rr
Thu, 19 Dec 2024 12:43:38 +0100
branchtransitional_engine
changeset 16051 a5eaeefa4ab3
permissions -rw-r--r--
Add a benchmark for landgen
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16051
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
     1
use criterion::{black_box, criterion_group, criterion_main, Criterion};
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
     2
use integral_geometry::{Point, Rect, Size};
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
     3
use landgen;
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
     4
use landgen::{LandGenerationParameters, LandGenerator};
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
     5
use landgen::outline_template_based::outline_template::OutlineTemplate;
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
     6
use landgen::outline_template_based::template_based::TemplatedLandGenerator;
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
     7
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
     8
pub fn generate_outline(c: &mut Criterion) {
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
     9
    let template = OutlineTemplate {
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
    10
    islands: vec![
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
    11
        vec![
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
    12
            Rect::from_box(273, 273, 2048, 2048),
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
    13
            Rect::from_box(683, 683, 32, 63),
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
    14
            Rect::from_box(1092, 1092, 2048, 2048),
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
    15
        ],
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
    16
        vec![
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
    17
            Rect::from_box(1638, 1638, 2048, 2048),
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
    18
            Rect::from_box(2048, 2048, 32, 63),
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
    19
            Rect::from_box(2458, 2458, 2048, 2048),
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
    20
        ],
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
    21
        vec![
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
    22
            Rect::from_box(3004, 3004, 2048, 2048),
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
    23
            Rect::from_box(3413, 3413, 32, 63),
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
    24
            Rect::from_box(3823, 3823, 2048, 2048),
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
    25
        ],
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
    26
    ],
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
    27
    walls: vec![],
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
    28
    fill_points: vec![Point::new(1, 0)],
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
    29
    size: Size {
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
    30
        width: 4096,
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
    31
        height: 2048,
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
    32
    },
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
    33
    can_flip: false,
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
    34
    can_invert: false,
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
    35
    can_mirror: false,
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
    36
    is_negative: false,
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
    37
};
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
    38
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
    39
    let parameters = LandGenerationParameters::new(
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
    40
     0u16,
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
    41
     32768u16,
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
    42
     10,
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
    43
    false,
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
    44
     false
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
    45
    );
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
    46
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
    47
    c.bench_function("outline_generation", |b| b.iter(|| {
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
    48
        fn prng() -> impl Iterator<Item = u32> {
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
    49
            (0..).map(|i| (i as u64 * 31_234_773 % 2_017_234_567) as u32)
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
    50
        }
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
    51
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
    52
        let gen = TemplatedLandGenerator::new(black_box(template.clone()));
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
    53
        gen.generate_land(black_box(&parameters), &mut prng())
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
    54
    }));
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
    55
}
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
    56
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
    57
criterion_group!(benches, generate_outline);
a5eaeefa4ab3 Add a benchmark for landgen
unC0Rr
parents:
diff changeset
    58
criterion_main!(benches);