diff --git a/Bigfoot/Benchmarks/CMakeLists.txt b/Bigfoot/Benchmarks/CMakeLists.txt index 4c48d68..6219887 100644 --- a/Bigfoot/Benchmarks/CMakeLists.txt +++ b/Bigfoot/Benchmarks/CMakeLists.txt @@ -2,3 +2,6 @@ add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/AssetsForBenchmarking) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/Engine) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/Utils) +if(${TOOLMODE}) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/Tools) +endif() diff --git a/Bigfoot/Benchmarks/Tools/CMakeLists.txt b/Bigfoot/Benchmarks/Tools/CMakeLists.txt new file mode 100644 index 0000000..4f25147 --- /dev/null +++ b/Bigfoot/Benchmarks/Tools/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/SasquatchBaker) diff --git a/Bigfoot/Benchmarks/Tools/SasquatchBaker/CMakeLists.txt b/Bigfoot/Benchmarks/Tools/SasquatchBaker/CMakeLists.txt new file mode 100644 index 0000000..fb74bf8 --- /dev/null +++ b/Bigfoot/Benchmarks/Tools/SasquatchBaker/CMakeLists.txt @@ -0,0 +1,13 @@ +get_filename_component(PackageName ${CMAKE_CURRENT_SOURCE_DIR} NAME) +project(${PackageName}Benchmarks) + +bigfoot_create_package_benchmarks( + "Tools") + +target_link_libraries(${PROJECT_NAME} + PRIVATE + $) + +bigfoot_create_bigfile("Benchmarks/Tools") + +bigfoot_create_sasquatch_info() diff --git a/Bigfoot/Benchmarks/Tools/SasquatchBaker/Include/SasquatchBakerBenchmarks/BigFileInfo_generated.hpp b/Bigfoot/Benchmarks/Tools/SasquatchBaker/Include/SasquatchBakerBenchmarks/BigFileInfo_generated.hpp new file mode 100644 index 0000000..9b2a6fc --- /dev/null +++ b/Bigfoot/Benchmarks/Tools/SasquatchBaker/Include/SasquatchBakerBenchmarks/BigFileInfo_generated.hpp @@ -0,0 +1,22 @@ +// AUTO-GENERATED DO NOT TOUCH + +/********************************************************************* + * \file BigFileInfo.generated.hpp + * + *********************************************************************/ +#ifndef BIGFOOT_SASQUATCHBAKERBENCHMARKS_BIGFILEINFO_GENERATED_HPP +#define BIGFOOT_SASQUATCHBAKERBENCHMARKS_BIGFILEINFO_GENERATED_HPP + +#include + +#if defined BIGFOOT_TOOLMODE + +namespace Bigfoot +{ +/* + * BigFile location + */ +constexpr eastl::string_view BIGFILE_SASQUATCHBAKERBENCHMARKS_LOCATION {"./SasquatchBakerBenchmarks-bigfile.db"}; +} // namespace Bigfoot +#endif +#endif diff --git a/Bigfoot/Benchmarks/Tools/SasquatchBaker/Include/SasquatchBakerBenchmarks/SasquatchInfo_generated.hpp b/Bigfoot/Benchmarks/Tools/SasquatchBaker/Include/SasquatchBakerBenchmarks/SasquatchInfo_generated.hpp new file mode 100644 index 0000000..f565bd0 --- /dev/null +++ b/Bigfoot/Benchmarks/Tools/SasquatchBaker/Include/SasquatchBakerBenchmarks/SasquatchInfo_generated.hpp @@ -0,0 +1,22 @@ +// AUTO-GENERATED DO NOT TOUCH + +/********************************************************************* + * \file SasquatchInfo.generated.hpp + * + *********************************************************************/ +#ifndef BIGFOOT_SASQUATCHBAKERBENCHMARKS_SASQUATCHINFO_GENERATED_HPP +#define BIGFOOT_SASQUATCHBAKERBENCHMARKS_SASQUATCHINFO_GENERATED_HPP + +#include + +#if defined BIGFOOT_GAME + +namespace Bigfoot +{ +/* + * Sasquatch location + */ +constexpr eastl::string_view SASQUATCH_SASQUATCHBAKERBENCHMARKS_LOCATION {"./SasquatchBakerBenchmarks-sasquatch.sasquatch"}; +} // namespace Bigfoot +#endif +#endif diff --git a/Bigfoot/Benchmarks/Tools/SasquatchBaker/SasquatchBaker.cpp b/Bigfoot/Benchmarks/Tools/SasquatchBaker/SasquatchBaker.cpp new file mode 100644 index 0000000..ec57a6f --- /dev/null +++ b/Bigfoot/Benchmarks/Tools/SasquatchBaker/SasquatchBaker.cpp @@ -0,0 +1,92 @@ +/********************************************************************* + * \file SasquatchBaker.cpp + * + * \author Romain BOULLARD + * \date August 2026 + *********************************************************************/ +#include + +#include +#include + +#include + +#include + +#include + +#include +#include + +#include +#include + +// SasquatchInfo_generated.hpp only exposes SASQUATCH_..._LOCATION in BIGFOOT_GAME builds, but this +// benchmark needs it to bake into a Sasquatch file from toolmode. Fake the macro locally rather than +// widening the shared template. +#define BIGFOOT_GAME +#include +#undef BIGFOOT_GAME + +namespace Bigfoot +{ +class SasquatchBakerFixture: public benchmark::Fixture +{ + protected: + static constexpr std::uint32_t ASSET_COUNT = 20'000; + static constexpr std::size_t ASSET_PAYLOAD_SIZE = 256; + + void SetUp(benchmark::State&) override + { + BigFile::Request {m_bigFile, "DELETE FROM Asset;"}.Execute(); + BigFile::Request {m_bigFile, "DELETE FROM AssetMetadata;"}.Execute(); + m_sasquatch.Delete(); + + eastl::vector metadatas; + eastl::vector> flatbuffers; + metadatas.reserve(ASSET_COUNT); + flatbuffers.reserve(ASSET_COUNT); + + for (std::uint32_t i = 0; i < ASSET_COUNT; ++i) + { + BenchmarkAsset asset; + asset.SetName(asset.GetHeader().uuid.ToString().c_str()); + asset.GetAsset().payload.assign(ASSET_PAYLOAD_SIZE, std::uint8_t {0xAB}); + + metadatas.push_back(AssetMetadata {.m_uuid = asset.GetHeader().uuid, + .m_name = asset.GetHeader().name, + .m_typeID = asset.GetHeader().type_id, + .m_typeName = asset.GetHeader().type_name}); + flatbuffers.push_back(asset.Pack()); + } + + m_bigFile.SaveAssetFlatbuffers(metadatas, flatbuffers); + } + + void TearDown(benchmark::State&) override + { + m_sasquatch.Delete(); + } + + BigFile m_bigFile {File {BIGFILE_SASQUATCHBAKERBENCHMARKS_LOCATION}}; + File m_sasquatch {SASQUATCH_SASQUATCHBAKERBENCHMARKS_LOCATION}; +}; + +/****************************************************************************************/ + +BENCHMARK_DEFINE_F(SasquatchBakerFixture, Bake)(benchmark::State& state) +{ + std::int64_t bytesProcessed = 0; + + for (auto _: state) + { + Bake(m_bigFile, m_sasquatch); + bytesProcessed += static_cast(m_sasquatch.GetSize()); + } + + state.SetItemsProcessed(state.iterations() * ASSET_COUNT); + state.SetBytesProcessed(bytesProcessed); +} + +BENCHMARK_REGISTER_F(SasquatchBakerFixture, Bake)->Name("SasquatchBaker/Bake")->Unit(benchmark::kMillisecond); +} // namespace Bigfoot