Address review comments for benchsimulate

This commit is contained in:
Michał Janiszewski 2021-01-10 13:33:53 +01:00
parent a8c3ca72ed
commit deebd779a9
3 changed files with 11 additions and 9 deletions

View File

@ -369,7 +369,7 @@ void GameState::UpdateLogic(LogicTimings* timings)
if (timings != nullptr)
{
timings->CurrentIdx = (timings->CurrentIdx + 1) % LOGIC_UPDATE_MEASURMENTS_COUNT;
timings->CurrentIdx = (timings->CurrentIdx + 1) % LOGIC_UPDATE_MEASUREMENTS_COUNT;
}
}

View File

@ -13,8 +13,8 @@
#include <array>
#include <chrono>
#include <map>
#include <memory>
#include <unordered_map>
namespace OpenRCT2
{
@ -48,10 +48,11 @@ namespace OpenRCT2
};
// ~6.5s at 40Hz
constexpr size_t LOGIC_UPDATE_MEASURMENTS_COUNT = 256;
constexpr size_t LOGIC_UPDATE_MEASUREMENTS_COUNT = 256;
// In order not to cause allocations, collect multiple samples into single pre-allocated struct
using LogicTimingInfo = std::map<LogicTimePart, std::array<std::chrono::duration<double>, LOGIC_UPDATE_MEASURMENTS_COUNT>>;
using LogicTimingInfo = std::unordered_map<
LogicTimePart, std::array<std::chrono::duration<double>, LOGIC_UPDATE_MEASUREMENTS_COUNT>>;
struct LogicTimings
{

View File

@ -20,6 +20,7 @@
# include <benchmark/benchmark.h>
# include <cstdint>
# include <iterator>
# include <numeric>
# include <vector>
using namespace OpenRCT2;
@ -39,7 +40,7 @@ static void BM_update(benchmark::State& state, const std::string& filename)
int currentTimingIdx = 0;
for (auto _ : state)
{
if (timings[currentTimingIdx].CurrentIdx == (LOGIC_UPDATE_MEASURMENTS_COUNT - 1))
if (timings[currentTimingIdx].CurrentIdx == (LOGIC_UPDATE_MEASUREMENTS_COUNT - 1))
{
timings.resize(timings.size() + 1);
currentTimingIdx++;
@ -52,8 +53,8 @@ static void BM_update(benchmark::State& state, const std::string& filename)
std::chrono::duration<double> timesum;
for (const auto& timing : timings)
{
for (const auto& PartTime : timing.TimingInfo.at(part))
timesum += PartTime;
timesum = std::accumulate(
timing.TimingInfo.at(part).begin(), timing.TimingInfo.at(part).end(), std::chrono::duration<double>());
}
return std::chrono::duration_cast<std::chrono::milliseconds>(timesum).count();
};
@ -86,7 +87,7 @@ static void BM_update(benchmark::State& state, const std::string& filename)
}
}
static int cmdline_for_bench_sprite_sort(int argc, const char* const* argv)
static int CmdlineForBenchSpriteSort(int argc, const char* const* argv)
{
// Add a baseline test on an empty park
benchmark::RegisterBenchmark("baseline", BM_update, std::string{});
@ -128,7 +129,7 @@ static exitcode_t HandleBenchUpdate(CommandLineArgEnumerator* argEnumerator)
{
const char* const* argv = static_cast<const char* const*>(argEnumerator->GetArguments()) + argEnumerator->GetIndex();
int32_t argc = argEnumerator->GetCount() - argEnumerator->GetIndex();
int32_t result = cmdline_for_bench_sprite_sort(argc, argv);
int32_t result = CmdlineForBenchSpriteSort(argc, argv);
if (result < 0)
{
return EXITCODE_FAIL;