summaryrefslogtreecommitdiffhomepage
path: root/bench/loader.cpp
blob: 6e891ab76c5181f1da91bf16fea5534ce4d91de1 (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
#include "loader/loader.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 {

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

    // warmup
    {   for (const auto& x : loader.anim_atlas_list())
            json_helper::from_json<anim_def>(Path::join(loader.ANIM_PATH, ""_s.join({x, ".json"})));
        json_helper::from_json<std::vector<nlohmann::json>>(Path::join(loader.VOBJ_PATH, "vobj.json"));
    }

    for (auto _ : state)
        for (int i = 0; i < 10; i++)
        {
            for (const auto& x : loader.anim_atlas_list())
                json_helper::from_json<anim_def>(Path::join(loader.ANIM_PATH, ""_s.join({x, ".json"})));
            json_helper::from_json<std::vector<nlohmann::json>>(Path::join(loader.VOBJ_PATH, "vobj.json"));
        }
}

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

} // namespace

} // namespace floormat