DomFixtures.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. #pragma once
  9. #include <AzCore/DOM/DomUtils.h>
  10. #include <AzCore/JSON/document.h>
  11. #include <AzCore/UnitTest/TestTypes.h>
  12. #define DOM_REGISTER_SERIALIZATION_BENCHMARK(BaseClass, Method) \
  13. BENCHMARK_REGISTER_F(BaseClass, Method)->Args({ 10, 5 })->Args({ 10, 500 })->Args({ 100, 5 })->Args({ 100, 500 })
  14. #define DOM_REGISTER_SERIALIZATION_BENCHMARK_MS(BaseClass, Method) \
  15. DOM_REGISTER_SERIALIZATION_BENCHMARK(BaseClass, Method)->Unit(benchmark::kMillisecond);
  16. #define DOM_REGISTER_SERIALIZATION_BENCHMARK_NS(BaseClass, Method) \
  17. DOM_REGISTER_SERIALIZATION_BENCHMARK(BaseClass, Method)->Unit(benchmark::kNanosecond);
  18. namespace AZ::Dom::Tests
  19. {
  20. class DomTestHarness
  21. {
  22. public:
  23. virtual ~DomTestHarness() = default;
  24. virtual void SetUpHarness();
  25. virtual void TearDownHarness();
  26. };
  27. class DomBenchmarkFixture
  28. : public DomTestHarness
  29. , public UnitTest::AllocatorsBenchmarkFixture
  30. {
  31. public:
  32. void SetUp(const ::benchmark::State& st) override;
  33. void SetUp(::benchmark::State& st) override;
  34. void TearDown(::benchmark::State& st) override;
  35. void TearDown(const ::benchmark::State& st) override;
  36. rapidjson::Document GenerateDomJsonBenchmarkDocument(int64_t entryCount, int64_t stringTemplateLength);
  37. AZStd::string GenerateDomJsonBenchmarkPayload(int64_t entryCount, int64_t stringTemplateLength);
  38. Value GenerateDomBenchmarkPayload(int64_t entryCount, int64_t stringTemplateLength);
  39. template<class T>
  40. static void TakeAndDiscardWithoutTimingDtor(T&& value, benchmark::State& state)
  41. {
  42. {
  43. T instance = AZStd::move(value);
  44. state.PauseTiming();
  45. }
  46. state.ResumeTiming();
  47. }
  48. };
  49. class DomTestFixture
  50. : public DomTestHarness
  51. , public UnitTest::LeakDetectionFixture
  52. {
  53. public:
  54. void SetUp() override;
  55. void TearDown() override;
  56. };
  57. } // namespace AZ::Dom::Tests