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