aboutsummaryrefslogtreecommitdiff
path: root/benches/rendering.rs
blob: 81b2e44368fd2572c67337425148e666e2d62eec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use criterion::{Criterion, criterion_group, criterion_main};
use std::hint::black_box;
use std::fs;
use wmap_renderer::{Configuration, StageType, render_to_surface};

fn benchmark_rendering(c: &mut Criterion) {
    let configuration = Configuration::default();

    let mut configuration_no_smart = Configuration::default();
    configuration_no_smart.options.smart_label_positioning = false;

    let example_source =
        fs::read_to_string("benches/example.wmap").expect("Failed to read benches/example.wmap");
    let example_map = wmap_parser::parse(&example_source);

    c.bench_function("render example map", |b| {
        b.iter(|| {
            render_to_surface(
                black_box(&example_map),
                StageType::default(),
                &configuration,
            )
        });
    });
    c.bench_function("render example map (no smart labels))", |b| {
        b.iter(|| {
            render_to_surface(
                black_box(&example_map),
                StageType::default(),
                &configuration_no_smart,
            )
        });
    });

    let huge_source =
        fs::read_to_string("benches/huge.wmap").expect("Failed to read benches/huge.wmap");
    let huge_map = wmap_parser::parse(&huge_source);

    c.bench_function("render huge map", |b| {
        b.iter(|| render_to_surface(black_box(&huge_map), StageType::default(), &configuration));
    });
    c.bench_function("render huge map", |b| {
        b.iter(|| {
            render_to_surface(
                black_box(&huge_map),
                StageType::default(),
                &configuration_no_smart,
            )
        });
    });
}

criterion_group!(benches, benchmark_rendering);
criterion_main!(benches);