PrefabInstantiateBenchmarks.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. namespace Benchmark
  11. {
  12. using BM_PrefabInstantiate = BM_Prefab;
  13. using namespace AzToolsFramework::Prefab;
  14. BENCHMARK_DEFINE_F(BM_PrefabInstantiate, InstantiatePrefab_SingleEntityInstance)(::benchmark::State& state)
  15. {
  16. const unsigned int numInstances = static_cast<unsigned int>(state.range());
  17. AZStd::unique_ptr<Instance> firstInstance = m_prefabSystemComponent->CreatePrefab(
  18. { CreateEntity("Entity1") },
  19. {},
  20. m_pathString);
  21. TemplateId templateToInstantiateId = firstInstance->GetTemplateId();
  22. for ([[maybe_unused]] auto _ : state)
  23. {
  24. state.PauseTiming();
  25. AZStd::vector<AZStd::unique_ptr<Instance>> newInstances;
  26. newInstances.resize(numInstances);
  27. state.ResumeTiming();
  28. for (unsigned int instanceCounter = 0; instanceCounter < numInstances; ++instanceCounter)
  29. {
  30. newInstances[instanceCounter] = m_prefabSystemComponent->InstantiatePrefab(templateToInstantiateId);
  31. }
  32. }
  33. state.SetComplexityN(numInstances);
  34. }
  35. BENCHMARK_REGISTER_F(BM_PrefabInstantiate, InstantiatePrefab_SingleEntityInstance)
  36. ->RangeMultiplier(10)
  37. ->Range(100, 10000)
  38. ->Unit(benchmark::kMillisecond)
  39. ->Complexity();
  40. }
  41. #endif