From 740f409a095604b6a60023346d4afd11e0f76b06 Mon Sep 17 00:00:00 2001 From: elsid Date: Sat, 8 Apr 2023 01:07:13 +0200 Subject: [PATCH] Add benchmarks for ESM3ExteriorCellRefId serialization --- apps/benchmarks/esm/benchrefid.cpp | 46 ++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/apps/benchmarks/esm/benchrefid.cpp b/apps/benchmarks/esm/benchrefid.cpp index c2cd41e093..b12f494ab9 100644 --- a/apps/benchmarks/esm/benchrefid.cpp +++ b/apps/benchmarks/esm/benchrefid.cpp @@ -82,6 +82,23 @@ namespace return generateSerializedRefIds(generateGeneratedRefIds(random), serialize); } + template + std::vector generateESM3ExteriorCellRefIds(Random& random) + { + std::vector result; + result.reserve(refIdsCount); + std::uniform_int_distribution distribution(-100, 100); + std::generate_n(std::back_inserter(result), refIdsCount, + [&] { return ESM::ESM3ExteriorCellRefId(distribution(random), distribution(random)); }); + return result; + } + + template + std::vector 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 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 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();