mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-16 16:29:55 +00:00
Add benchmarks for ESM3ExteriorCellRefId serialization
This commit is contained in:
parent
794050df63
commit
740f409a09
1 changed files with 46 additions and 0 deletions
|
@ -82,6 +82,23 @@ namespace
|
|||
return generateSerializedRefIds(generateGeneratedRefIds(random), serialize);
|
||||
}
|
||||
|
||||
template <class Random>
|
||||
std::vector<ESM::RefId> generateESM3ExteriorCellRefIds(Random& random)
|
||||
{
|
||||
std::vector<ESM::RefId> result;
|
||||
result.reserve(refIdsCount);
|
||||
std::uniform_int_distribution<std::int32_t> distribution(-100, 100);
|
||||
std::generate_n(std::back_inserter(result), refIdsCount,
|
||||
[&] { return ESM::ESM3ExteriorCellRefId(distribution(random), distribution(random)); });
|
||||
return result;
|
||||
}
|
||||
|
||||
template <class Random, class Serialize>
|
||||
std::vector<std::string> generateSerializedESM3ExteriorCellRefIds(Random& random, Serialize&& serialize)
|
||||
{
|
||||
return generateSerializedRefIds(generateESM3ExteriorCellRefIds(random), serialize);
|
||||
}
|
||||
|
||||
void serializeRefId(benchmark::State& state)
|
||||
{
|
||||
std::minstd_rand random;
|
||||
|
@ -189,6 +206,33 @@ namespace
|
|||
i = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void serializeTextESM3ExteriorCellRefId(benchmark::State& state)
|
||||
{
|
||||
std::minstd_rand random;
|
||||
std::vector<ESM::RefId> refIds = generateESM3ExteriorCellRefIds(random);
|
||||
std::size_t i = 0;
|
||||
for (auto _ : state)
|
||||
{
|
||||
benchmark::DoNotOptimize(refIds[i].serializeText());
|
||||
if (++i >= refIds.size())
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void deserializeTextESM3ExteriorCellRefId(benchmark::State& state)
|
||||
{
|
||||
std::minstd_rand random;
|
||||
std::vector<std::string> serializedRefIds
|
||||
= generateSerializedESM3ExteriorCellRefIds(random, [](ESM::RefId v) { return v.serializeText(); });
|
||||
std::size_t i = 0;
|
||||
for (auto _ : state)
|
||||
{
|
||||
benchmark::DoNotOptimize(ESM::RefId::deserializeText(serializedRefIds[i]));
|
||||
if (++i >= serializedRefIds.size())
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BENCHMARK(serializeRefId)->RangeMultiplier(4)->Range(8, 64);
|
||||
|
@ -199,5 +243,7 @@ BENCHMARK(serializeTextGeneratedRefId);
|
|||
BENCHMARK(deserializeTextGeneratedRefId);
|
||||
BENCHMARK(serializeTextIndexRefId);
|
||||
BENCHMARK(deserializeTextIndexRefId);
|
||||
BENCHMARK(serializeTextESM3ExteriorCellRefId);
|
||||
BENCHMARK(deserializeTextESM3ExteriorCellRefId);
|
||||
|
||||
BENCHMARK_MAIN();
|
||||
|
|
Loading…
Reference in a new issue