SpawnableCreateBenchmarks.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #if defined(HAVE_BENCHMARK)
  9. #include <Prefab/Benchmark/PrefabBenchmarkFixture.h>
  10. #include <AzToolsFramework/Prefab/Spawnable/SpawnableUtils.h>
  11. namespace Benchmark
  12. {
  13. using BM_SpawnableCreate = BM_Prefab;
  14. using namespace AzToolsFramework::Prefab;
  15. BENCHMARK_DEFINE_F(BM_SpawnableCreate, CreateSpawnable_SingleEntityInstance)(::benchmark::State& state)
  16. {
  17. const unsigned int numSpawnables = static_cast<unsigned int>(state.range());
  18. AZStd::unique_ptr<Instance> instance(m_prefabSystemComponent->CreatePrefab(
  19. { CreateEntity("Entity1") },
  20. {},
  21. m_pathString));
  22. auto& prefabDom = m_prefabSystemComponent->FindTemplateDom(instance->GetTemplateId());
  23. for ([[maybe_unused]] auto _ : state)
  24. {
  25. // Create a vector to store spawnables so that they don't get destroyed immediately after construction.
  26. AZStd::vector<AZStd::unique_ptr<AzFramework::Spawnable>> spawnables;
  27. spawnables.reserve(numSpawnables);
  28. for (unsigned int spwanableCounter = 0; spwanableCounter < numSpawnables; ++spwanableCounter)
  29. {
  30. AZStd::unique_ptr<AzFramework::Spawnable> spawnable = AZStd::make_unique<AzFramework::Spawnable>();
  31. AzToolsFramework::Prefab::SpawnableUtils::CreateSpawnable(*spawnable, prefabDom);
  32. spawnables.push_back(AZStd::move(spawnable));
  33. }
  34. }
  35. state.SetComplexityN(numSpawnables);
  36. }
  37. BENCHMARK_REGISTER_F(BM_SpawnableCreate, CreateSpawnable_SingleEntityInstance)
  38. ->RangeMultiplier(10)
  39. ->Range(100, 10000)
  40. ->Unit(benchmark::kMillisecond)
  41. ->Complexity();
  42. }
  43. #endif