175 lines
4.9 KiB
C++
175 lines
4.9 KiB
C++
/*********************************************************************
|
|
* \file AssetContainer.cpp
|
|
*
|
|
* \author Romain BOULLARD
|
|
* \date August 2026
|
|
*********************************************************************/
|
|
#include <Engine/Asset/AssetContainer.hpp>
|
|
|
|
#include <AssetsForBenchmarking/Asset/BenchmarkAsset.hpp>
|
|
|
|
#include <benchmark/benchmark.h>
|
|
#include <effolkronium/random.hpp>
|
|
|
|
#include <cstdint>
|
|
|
|
namespace Bigfoot
|
|
{
|
|
namespace
|
|
{
|
|
using Random = effolkronium::random_static;
|
|
} // namespace
|
|
|
|
/****************************************************************************************/
|
|
|
|
void Insert(benchmark::State& state)
|
|
{
|
|
const auto count = static_cast<std::uint32_t>(state.range(0));
|
|
|
|
for (auto _: state)
|
|
{
|
|
AssetContainer<BenchmarkAsset> container;
|
|
for (std::uint32_t i = 0; i < count; ++i)
|
|
{
|
|
benchmark::DoNotOptimize(container.Insert());
|
|
}
|
|
benchmark::DoNotOptimize(container);
|
|
benchmark::ClobberMemory();
|
|
}
|
|
|
|
state.SetItemsProcessed(state.iterations() * count);
|
|
state.SetBytesProcessed(static_cast<std::int64_t>(state.iterations() * count * sizeof(BenchmarkAsset)));
|
|
}
|
|
|
|
BENCHMARK(Insert)->Name("AssetContainer/Insert")->Arg(512)->Arg(8192)->Arg(131'072);
|
|
|
|
/****************************************************************************************/
|
|
|
|
void Get(benchmark::State& state)
|
|
{
|
|
const auto count = static_cast<std::uint32_t>(state.range(0));
|
|
|
|
AssetContainer<BenchmarkAsset> container;
|
|
eastl::vector<SlotMapKey<>> keys;
|
|
keys.reserve(count);
|
|
for (std::uint32_t i = 0; i < count; ++i)
|
|
{
|
|
keys.push_back(container.Insert());
|
|
}
|
|
Random::shuffle(keys);
|
|
|
|
for (auto _: state)
|
|
{
|
|
std::uint64_t sum = 0;
|
|
for (const SlotMapKey<> key: keys)
|
|
{
|
|
if (const BenchmarkAsset* const asset = container.Get(key))
|
|
{
|
|
sum += asset->GetHeader().type_id;
|
|
}
|
|
}
|
|
benchmark::DoNotOptimize(sum);
|
|
}
|
|
|
|
state.SetItemsProcessed(state.iterations() * count);
|
|
}
|
|
|
|
BENCHMARK(Get)->Name("AssetContainer/Get")->Arg(512)->Arg(8192)->Arg(131'072);
|
|
|
|
/****************************************************************************************/
|
|
|
|
void Has(benchmark::State& state)
|
|
{
|
|
const auto count = static_cast<std::uint32_t>(state.range(0));
|
|
|
|
AssetContainer<BenchmarkAsset> container;
|
|
eastl::vector<UUID> uuids;
|
|
uuids.reserve(count);
|
|
for (std::uint32_t i = 0; i < count; ++i)
|
|
{
|
|
const SlotMapKey<> key = container.Insert();
|
|
uuids.push_back(container.Get(key)->GetHeader().uuid);
|
|
}
|
|
Random::shuffle(uuids);
|
|
|
|
for (auto _: state)
|
|
{
|
|
bool result = true;
|
|
for (const UUID& uuid: uuids)
|
|
{
|
|
result = result && container.Has(uuid);
|
|
}
|
|
benchmark::DoNotOptimize(result);
|
|
}
|
|
|
|
state.SetItemsProcessed(state.iterations() * count);
|
|
}
|
|
|
|
BENCHMARK(Has)->Name("AssetContainer/Has")->Arg(512)->Arg(8192)->Arg(131'072);
|
|
|
|
/****************************************************************************************/
|
|
|
|
void AcquireContainerHandle(benchmark::State& state)
|
|
{
|
|
const auto count = static_cast<std::uint32_t>(state.range(0));
|
|
|
|
AssetContainer<BenchmarkAsset> container;
|
|
eastl::vector<UUID> uuids;
|
|
uuids.reserve(count);
|
|
for (std::uint32_t i = 0; i < count; ++i)
|
|
{
|
|
const SlotMapKey<> key = container.Insert();
|
|
uuids.push_back(container.Get(key)->GetHeader().uuid);
|
|
}
|
|
Random::shuffle(uuids);
|
|
|
|
for (auto _: state)
|
|
{
|
|
std::uint64_t sum = 0;
|
|
for (const UUID& uuid: uuids)
|
|
{
|
|
sum += container.AcquireContainerHandle(uuid)->GetHardRefCount();
|
|
}
|
|
benchmark::DoNotOptimize(sum);
|
|
}
|
|
|
|
state.SetItemsProcessed(state.iterations() * count);
|
|
}
|
|
|
|
BENCHMARK(AcquireContainerHandle)->Name("AssetContainer/AcquireContainerHandle")->Arg(512)->Arg(8192)->Arg(131'072);
|
|
|
|
/****************************************************************************************/
|
|
|
|
void Remove(benchmark::State& state)
|
|
{
|
|
const auto count = static_cast<std::uint32_t>(state.range(0));
|
|
|
|
AssetContainer<BenchmarkAsset> container;
|
|
eastl::vector<UUID> uuids;
|
|
uuids.reserve(count);
|
|
|
|
for (auto _: state)
|
|
{
|
|
state.PauseTiming();
|
|
uuids.clear();
|
|
for (std::uint32_t i = 0; i < count; ++i)
|
|
{
|
|
const SlotMapKey<> key = container.Insert();
|
|
uuids.push_back(container.Get(key)->GetHeader().uuid);
|
|
}
|
|
Random::shuffle(uuids);
|
|
state.ResumeTiming();
|
|
|
|
for (const UUID& uuid: uuids)
|
|
{
|
|
container.Remove(uuid);
|
|
}
|
|
}
|
|
|
|
state.SetItemsProcessed(state.iterations() * count);
|
|
state.SetBytesProcessed(static_cast<std::int64_t>(state.iterations() * count * sizeof(BenchmarkAsset)));
|
|
}
|
|
|
|
BENCHMARK(Remove)->Name("AssetContainer/Remove")->Arg(512)->Arg(8192)->Arg(131'072);
|
|
} // namespace Bigfoot
|