Skip to content

Commit

Permalink
Change: Set thread & process priorities in tests/benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
spnda committed Apr 21, 2024
1 parent 7352629 commit f2aab63
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion fetch_test_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
'imgui': "https://github.com/ocornut/imgui/archive/refs/tags/v1.90.4.zip"
}
test_deps_urls = {
'catch2': "https://github.com/catchorg/Catch2/archive/refs/tags/v3.5.2.zip",
'catch2': "https://github.com/catchorg/Catch2/archive/refs/tags/v3.5.4.zip",
'corrosion': "https://github.com/corrosion-rs/corrosion/archive/refs/heads/master.zip",
}
deps_folder = "deps/"
Expand Down
9 changes: 2 additions & 7 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
set_directory_properties(PROPERTIES EXCLUDE_FROM_ALL TRUE)

# We want these tests to be a optional executable.
add_executable(fastgltf_tests EXCLUDE_FROM_ALL
add_executable(fastgltf_tests EXCLUDE_FROM_ALL "main.cpp"
"base64_tests.cpp" "basic_test.cpp" "benchmarks.cpp" "glb_tests.cpp" "gltf_path.hpp" "util_tests.cpp"
"vector_tests.cpp" "uri_tests.cpp" "extension_tests.cpp" "accessor_tests.cpp" "write_tests.cpp")
target_compile_features(fastgltf_tests PRIVATE ${FASTGLTF_COMPILE_TARGET})
target_link_libraries(fastgltf_tests PRIVATE fastgltf)
target_link_libraries(fastgltf_tests PRIVATE glm::glm Catch2::Catch2WithMain)
target_link_libraries(fastgltf_tests PRIVATE glm::glm Catch2::Catch2)
fastgltf_compiler_flags(fastgltf_tests)

if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/deps/catch2")
add_subdirectory(deps/catch2)
target_link_libraries(fastgltf_tests PRIVATE Catch2::Catch2)
endif()

# We only use tinygltf to compare against.
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/gltf_loaders/tinygltf/tiny_gltf.h")
message(STATUS "fastgltf: Found tinygltf")
Expand Down
4 changes: 2 additions & 2 deletions tests/benchmarks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ void setTinyGLTFCallbacks(tinygltf::TinyGLTF& gltf) {
#include <assimp/Base64.hpp>
#endif

std::vector<uint8_t> readFileAsBytes(const std::filesystem::path& path) {
fastgltf::StaticVector<std::uint8_t> readFileAsBytes(const std::filesystem::path& path) {
std::ifstream file(path, std::ios::ate | std::ios::binary);
if (!file.is_open())
throw std::runtime_error(std::string { "Failed to open file: " } + path.string());

auto fileSize = file.tellg();
std::vector<uint8_t> bytes(static_cast<size_t>(fileSize) + fastgltf::getGltfBufferPadding());
fastgltf::StaticVector<std::uint8_t> bytes(static_cast<std::size_t>(fileSize) + fastgltf::getGltfBufferPadding());
file.seekg(0, std::ifstream::beg);
file.read(reinterpret_cast<char*>(bytes.data()), fileSize);
file.close();
Expand Down
15 changes: 15 additions & 0 deletions tests/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <catch2/catch_session.hpp>

#ifdef _WIN32
#include <windows.h>
#endif

// See https://github.com/catchorg/Catch2/blob/v3.5.4/docs/own-main.md
int main(int argc, char* argv[]) {
#if defined(_WIN32) && defined(NDEBUG)
// Guarantee the best performance and result stability across runs
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
#endif
return Catch::Session().run(argc, argv);
}

0 comments on commit f2aab63

Please sign in to comment.