From e5d5c5167318e90751fad3aee58a0356bb6af699 Mon Sep 17 00:00:00 2001 From: elsid Date: Fri, 3 Feb 2023 15:30:58 +0100 Subject: [PATCH] Add benchmarks for settings access --- apps/benchmarks/CMakeLists.txt | 1 + apps/benchmarks/settings/CMakeLists.txt | 15 +++++ apps/benchmarks/settings/access.cpp | 86 +++++++++++++++++++++++++ 3 files changed, 102 insertions(+) create mode 100644 apps/benchmarks/settings/CMakeLists.txt create mode 100644 apps/benchmarks/settings/access.cpp diff --git a/apps/benchmarks/CMakeLists.txt b/apps/benchmarks/CMakeLists.txt index 971a1ecd25..8039f2a3d2 100644 --- a/apps/benchmarks/CMakeLists.txt +++ b/apps/benchmarks/CMakeLists.txt @@ -4,3 +4,4 @@ endif() add_subdirectory(detournavigator) add_subdirectory(esm) +add_subdirectory(settings) diff --git a/apps/benchmarks/settings/CMakeLists.txt b/apps/benchmarks/settings/CMakeLists.txt new file mode 100644 index 0000000000..bc2f8cd44b --- /dev/null +++ b/apps/benchmarks/settings/CMakeLists.txt @@ -0,0 +1,15 @@ +openmw_add_executable(openmw_settings_access_benchmark access.cpp) +target_link_libraries(openmw_settings_access_benchmark benchmark::benchmark components) + +if (UNIX AND NOT APPLE) + target_link_libraries(openmw_settings_access_benchmark ${CMAKE_THREAD_LIBS_INIT}) +endif() + +if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.16 AND MSVC) + target_precompile_headers(openmw_settings_access_benchmark PRIVATE ) +endif() + +if (BUILD_WITH_CODE_COVERAGE) + target_compile_options(openmw_settings_access_benchmark PRIVATE --coverage) + target_link_libraries(openmw_settings_access_benchmark gcov) +endif() diff --git a/apps/benchmarks/settings/access.cpp b/apps/benchmarks/settings/access.cpp new file mode 100644 index 0000000000..468debec91 --- /dev/null +++ b/apps/benchmarks/settings/access.cpp @@ -0,0 +1,86 @@ +#include + +#include +#include +#include + +#include + +#include +#include + +namespace +{ + namespace bpo = boost::program_options; + + bpo::options_description makeOptionsDescription() + { + bpo::options_description result; + auto addOption = result.add_options(); + addOption("help", "print help message"); + Files::ConfigurationManager::addCommonOptions(result); + return result; + } + + void settingsManager(benchmark::State& state) + { + for (auto _ : state) + { + benchmark::DoNotOptimize(Settings::Manager::getFloat("sky blending start", "Fog")); + } + } + + void localStatic(benchmark::State& state) + { + for (auto _ : state) + { + static const float v = Settings::Manager::getFloat("sky blending start", "Fog"); + benchmark::DoNotOptimize(v); + } + } + + void settingsStorage(benchmark::State& state) + { + for (auto _ : state) + { + benchmark::DoNotOptimize(Settings::fog().mSkyBlendingStart.get()); + } + } +} + +BENCHMARK(settingsManager); +BENCHMARK(localStatic); +BENCHMARK(settingsStorage); + +int main(int argc, char* argv[]) +{ + bpo::options_description desc = makeOptionsDescription(); + + bpo::parsed_options options = bpo::command_line_parser(argc, argv).options(desc).allow_unregistered().run(); + bpo::variables_map variables; + + bpo::store(options, variables); + bpo::notify(variables); + + if (variables.find("help") != variables.end()) + { + std::cout << desc << std::endl; + benchmark::Initialize(&argc, argv); + benchmark::Shutdown(); + return 1; + } + + Files::ConfigurationManager config; + + bpo::variables_map composingVariables = Files::separateComposingVariables(variables, desc); + config.readConfiguration(variables, desc); + Files::mergeComposingVariables(variables, composingVariables, desc); + + Settings::Manager::load(config); + + benchmark::Initialize(&argc, argv); + benchmark::RunSpecifiedBenchmarks(); + benchmark::Shutdown(); + + return 0; +}