summaryrefslogtreecommitdiffhomepage
path: root/bench/loader.cpp
blob: dcd13e4e8a9742745c3511ba202ef2e303d4528a (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
55
56
57
58
59
60
61
62
63
#include "loader/loader.hpp"
#include "loader/ground-info.hpp"
#include "loader/wall-info.hpp"
#include "serialize/json-helper.hpp"
#include "serialize/anim.hpp"
#include <Corrade/Containers/ArrayView.h>
#include <Corrade/Containers/StringIterable.h>
#include <Corrade/Utility/Path.h>
#include <benchmark/benchmark.h>

namespace floormat {

namespace {

constexpr struct {
    const char* name;
    Vector2ub size;
    pass_mode pass = pass_mode::pass;
} ground_atlases[] = {
    { "floor-tiles", {44,4} },
    { "tiles", {8, 5} },
    { "texel", {2, 2}, pass_mode::blocked },
    { "metal1", {2,2} },
};

constexpr const char* wall_atlases[] = {
    "concrete1", "empty", "test1",
};

constexpr const char* anim_atlases[] = {
    "anim/npc-walk",
    "anim/test-8x8",
    "scenery/door-close",
    "scenery/control-panel",
    "scenery/table",
};

using nlohmann::json;

void run()
{
    for (const auto& str : anim_atlases)
        (void)loader.get_anim_atlas(str);
    for (const auto& x : ground_atlases)
        (void)loader.get_ground_atlas(x.name, x.size, x.pass);
    for (const auto& name : wall_atlases)
        (void)loader.get_wall_atlas(name);
}

void Loader_json(benchmark::State& state)
{
    loader.destroy();

    run();
    for (auto _ : state)
        run();
}

BENCHMARK(Loader_json)->Unit(benchmark::kMillisecond);

} // namespace

} // namespace floormat