1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-03-28 19:21:04 +00:00

Merge branch 'settings_access_bench' into 'master'

Run openmw_settings_access_benchmark in CI

See merge request OpenMW/openmw!2967
This commit is contained in:
psi29a 2023-04-25 11:42:47 +00:00
commit 94e467caa3
5 changed files with 93 additions and 42 deletions

View File

@ -74,6 +74,7 @@ Ubuntu_GCC_preprocess:
- if [[ "${BUILD_TESTS_ONLY}" ]]; then ./openmw-cs-tests --gtest_output="xml:openmw_cs_tests.xml"; fi - if [[ "${BUILD_TESTS_ONLY}" ]]; then ./openmw-cs-tests --gtest_output="xml:openmw_cs_tests.xml"; fi
- if [[ "${BUILD_TESTS_ONLY}" && ! "${BUILD_WITH_CODE_COVERAGE}" ]]; then ./openmw_detournavigator_navmeshtilescache_benchmark; fi - if [[ "${BUILD_TESTS_ONLY}" && ! "${BUILD_WITH_CODE_COVERAGE}" ]]; then ./openmw_detournavigator_navmeshtilescache_benchmark; fi
- if [[ "${BUILD_TESTS_ONLY}" && ! "${BUILD_WITH_CODE_COVERAGE}" ]]; then ./openmw_esm_refid_benchmark; fi - if [[ "${BUILD_TESTS_ONLY}" && ! "${BUILD_WITH_CODE_COVERAGE}" ]]; then ./openmw_esm_refid_benchmark; fi
- if [[ "${BUILD_TESTS_ONLY}" && ! "${BUILD_WITH_CODE_COVERAGE}" ]]; then ./openmw_settings_access_benchmark; fi
- ccache -s - ccache -s
- df -h - df -h
- if [[ "${BUILD_WITH_CODE_COVERAGE}" ]]; then gcovr --xml-pretty --exclude-unreachable-branches --print-summary --root "${CI_PROJECT_DIR}" -j $(nproc) -o ../coverage.xml; fi - if [[ "${BUILD_WITH_CODE_COVERAGE}" ]]; then gcovr --xml-pretty --exclude-unreachable-branches --print-summary --root "${CI_PROJECT_DIR}" -j $(nproc) -o ../coverage.xml; fi

View File

@ -1,6 +1,9 @@
openmw_add_executable(openmw_settings_access_benchmark access.cpp) openmw_add_executable(openmw_settings_access_benchmark access.cpp)
target_link_libraries(openmw_settings_access_benchmark benchmark::benchmark components) target_link_libraries(openmw_settings_access_benchmark benchmark::benchmark components)
target_compile_definitions(openmw_settings_access_benchmark
PRIVATE OPENMW_PROJECT_SOURCE_DIR=u8"${PROJECT_SOURCE_DIR}")
if (UNIX AND NOT APPLE) if (UNIX AND NOT APPLE)
target_link_libraries(openmw_settings_access_benchmark ${CMAKE_THREAD_LIBS_INIT}) target_link_libraries(openmw_settings_access_benchmark ${CMAKE_THREAD_LIBS_INIT})
endif() endif()

View File

@ -1,27 +1,12 @@
#include <benchmark/benchmark.h> #include <benchmark/benchmark.h>
#include <components/files/configurationmanager.hpp> #include "components/misc/strings/conversion.hpp"
#include <components/settings/settings.hpp> #include "components/settings/parser.hpp"
#include <components/settings/values.hpp> #include "components/settings/settings.hpp"
#include "components/settings/values.hpp"
#include <boost/program_options.hpp>
#include <algorithm>
#include <iostream>
namespace 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) void settingsManager(benchmark::State& state)
{ {
for (auto _ : state) for (auto _ : state)
@ -30,6 +15,25 @@ namespace
} }
} }
void settingsManager2(benchmark::State& state)
{
for (auto _ : state)
{
benchmark::DoNotOptimize(Settings::Manager::getFloat("near clip", "Camera"));
benchmark::DoNotOptimize(Settings::Manager::getBool("transparent postpass", "Post Processing"));
}
}
void settingsManager3(benchmark::State& state)
{
for (auto _ : state)
{
benchmark::DoNotOptimize(Settings::Manager::getFloat("near clip", "Camera"));
benchmark::DoNotOptimize(Settings::Manager::getBool("transparent postpass", "Post Processing"));
benchmark::DoNotOptimize(Settings::Manager::getInt("reflection detail", "Water"));
}
}
void localStatic(benchmark::State& state) void localStatic(benchmark::State& state)
{ {
for (auto _ : state) for (auto _ : state)
@ -39,6 +43,30 @@ namespace
} }
} }
void localStatic2(benchmark::State& state)
{
for (auto _ : state)
{
static const float v1 = Settings::Manager::getFloat("near clip", "Camera");
static const bool v2 = Settings::Manager::getBool("transparent postpass", "Post Processing");
benchmark::DoNotOptimize(v1);
benchmark::DoNotOptimize(v2);
}
}
void localStatic3(benchmark::State& state)
{
for (auto _ : state)
{
static const float v1 = Settings::Manager::getFloat("near clip", "Camera");
static const bool v2 = Settings::Manager::getBool("transparent postpass", "Post Processing");
static const int v3 = Settings::Manager::getInt("reflection detail", "Water");
benchmark::DoNotOptimize(v1);
benchmark::DoNotOptimize(v2);
benchmark::DoNotOptimize(v3);
}
}
void settingsStorage(benchmark::State& state) void settingsStorage(benchmark::State& state)
{ {
for (auto _ : state) for (auto _ : state)
@ -46,37 +74,55 @@ namespace
benchmark::DoNotOptimize(Settings::fog().mSkyBlendingStart.get()); benchmark::DoNotOptimize(Settings::fog().mSkyBlendingStart.get());
} }
} }
void settingsStorage2(benchmark::State& state)
{
for (auto _ : state)
{
benchmark::DoNotOptimize(Settings::postProcessing().mTransparentPostpass.get());
benchmark::DoNotOptimize(Settings::camera().mNearClip.get());
}
}
void settingsStorage3(benchmark::State& state)
{
for (auto _ : state)
{
benchmark::DoNotOptimize(Settings::postProcessing().mTransparentPostpass.get());
benchmark::DoNotOptimize(Settings::camera().mNearClip.get());
benchmark::DoNotOptimize(Settings::water().mReflectionDetail.get());
}
}
} }
BENCHMARK(settingsManager); BENCHMARK(settingsManager);
BENCHMARK(localStatic); BENCHMARK(localStatic);
BENCHMARK(settingsStorage); BENCHMARK(settingsStorage);
BENCHMARK(settingsManager2);
BENCHMARK(localStatic2);
BENCHMARK(settingsStorage2);
BENCHMARK(settingsManager3);
BENCHMARK(localStatic3);
BENCHMARK(settingsStorage3);
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
bpo::options_description desc = makeOptionsDescription(); const std::filesystem::path settingsDefaultPath = std::filesystem::path{ OPENMW_PROJECT_SOURCE_DIR } / "files"
/ Misc::StringUtils::stringToU8String("settings-default.cfg");
bpo::parsed_options options = bpo::command_line_parser(argc, argv).options(desc).allow_unregistered().run(); Settings::SettingsFileParser parser;
bpo::variables_map variables; parser.loadSettingsFile(settingsDefaultPath, Settings::Manager::mDefaultSettings);
bpo::store(options, variables); Settings::Values::initDefaults();
bpo::notify(variables);
if (variables.find("help") != variables.end()) Settings::Manager::mUserSettings = Settings::Manager::mDefaultSettings;
{ Settings::Manager::mUserSettings.erase({ "Camera", "near clip" });
std::cout << desc << std::endl; Settings::Manager::mUserSettings.erase({ "Post Processing", "transparent postpass" });
benchmark::Initialize(&argc, argv); Settings::Manager::mUserSettings.erase({ "Water", "reflection detail" });
benchmark::Shutdown();
return 1;
}
Files::ConfigurationManager config; Settings::Values::init();
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::Initialize(&argc, argv);
benchmark::RunSpecifiedBenchmarks(); benchmark::RunSpecifiedBenchmarks();

View File

@ -177,10 +177,8 @@ namespace Settings
if (it != mDefaultSettings.end()) if (it != mDefaultSettings.end())
return it->second; return it->second;
std::string error("Trying to retrieve a non-existing setting: "); throw std::runtime_error("Trying to retrieve a non-existing setting: [" + std::string(category) + "] "
error += setting; + std::string(setting) + ".\nMake sure the defaults.bin file was properly installed.");
error += ".\nMake sure the defaults.bin file was properly installed.";
throw std::runtime_error(error);
} }
std::vector<std::string> Manager::getStringArray(std::string_view setting, std::string_view category) std::vector<std::string> Manager::getStringArray(std::string_view setting, std::string_view category)

View File

@ -27,6 +27,8 @@
#include "categories/water.hpp" #include "categories/water.hpp"
#include "categories/windows.hpp" #include "categories/windows.hpp"
#include <cassert>
namespace Settings namespace Settings
{ {
class Values class Values
@ -70,6 +72,7 @@ namespace Settings
inline Values& values() inline Values& values()
{ {
assert(Values::sValues != nullptr);
return *Values::sValues; return *Values::sValues;
} }