From eb2b724902560d211d0a724a89487b8a2fd2bfa0 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Thu, 24 Jun 2021 14:04:35 +0200 Subject: [PATCH] benchmark: tombstone policy runs --- test/benchmark/benchmark.cpp | 106 +++++++++++++++++++++++++++++++++-- 1 file changed, 100 insertions(+), 6 deletions(-) diff --git a/test/benchmark/benchmark.cpp b/test/benchmark/benchmark.cpp index be2194e7c..a5e089b6c 100644 --- a/test/benchmark/benchmark.cpp +++ b/test/benchmark/benchmark.cpp @@ -12,14 +12,17 @@ struct position { std::uint64_t y; }; -struct velocity { - std::uint64_t x; - std::uint64_t y; -}; +struct velocity: position {}; +struct stable_position: position {}; template struct comp { int x; }; +template<> +struct entt::component_traits: basic_component_traits { + using in_place_delete = std::true_type; +}; + struct timer final { timer(): start{std::chrono::system_clock::now()} {} @@ -72,7 +75,7 @@ TEST(Benchmark, Create) { timer timer; for(std::uint64_t i = 0; i < 1000000L; i++) { - registry.create(); + static_cast(registry.create()); } timer.elapsed(); @@ -201,7 +204,7 @@ TEST(Benchmark, Recycle) { timer timer; for(auto next = entities.size(); next; --next) { - registry.create(); + static_cast(registry.create()); } timer.elapsed(); @@ -278,6 +281,27 @@ TEST(Benchmark, IterateSingleComponent1M) { }); } +TEST(Benchmark, IterateSingleComponentTombstonePolicy1M) { + entt::registry registry; + + std::cout << "Iterating over 1000000 entities, one component, tombstone policy" << std::endl; + + for(std::uint64_t i = 0; i < 1000000L; i++) { + const auto entity = registry.create(); + registry.emplace(entity); + } + + auto test = [&](auto func) { + timer timer; + registry.view().each(func); + timer.elapsed(); + }; + + test([](auto &... comp) { + ((comp.x = {}), ...); + }); +} + TEST(Benchmark, IterateSingleComponentRuntime1M) { entt::registry registry; @@ -323,6 +347,28 @@ TEST(Benchmark, IterateTwoComponents1M) { }); } +TEST(Benchmark, IterateTombstonePolicyTwoComponentsTombstonePolicy1M) { + entt::registry registry; + + std::cout << "Iterating over 1000000 entities, two components, tombstone policy" << std::endl; + + for(std::uint64_t i = 0; i < 1000000L; i++) { + const auto entity = registry.create(); + registry.emplace(entity); + registry.emplace(entity); + } + + auto test = [&](auto func) { + timer timer; + registry.view().each(func); + timer.elapsed(); + }; + + test([](auto &... comp) { + ((comp.x = {}), ...); + }); +} + TEST(Benchmark, IterateTwoComponents1MHalf) { entt::registry registry; @@ -555,6 +601,29 @@ TEST(Benchmark, IterateThreeComponents1M) { }); } +TEST(Benchmark, IterateThreeComponentsTombstonePolicy1M) { + entt::registry registry; + + std::cout << "Iterating over 1000000 entities, three components, tombstone policy" << std::endl; + + for(std::uint64_t i = 0; i < 1000000L; i++) { + const auto entity = registry.create(); + registry.emplace(entity); + registry.emplace(entity); + registry.emplace>(entity); + } + + auto test = [&](auto func) { + timer timer; + registry.view>().each(func); + timer.elapsed(); + }; + + test([](auto &... comp) { + ((comp.x = {}), ...); + }); +} + TEST(Benchmark, IterateThreeComponents1MHalf) { entt::registry registry; @@ -803,6 +872,31 @@ TEST(Benchmark, IterateFiveComponents1M) { }); } +TEST(Benchmark, IterateFiveComponentsTombstonePolicy1M) { + entt::registry registry; + + std::cout << "Iterating over 1000000 entities, five components, tombstone policy" << std::endl; + + for(std::uint64_t i = 0; i < 1000000L; i++) { + const auto entity = registry.create(); + registry.emplace(entity); + registry.emplace(entity); + registry.emplace>(entity); + registry.emplace>(entity); + registry.emplace>(entity); + } + + auto test = [&](auto func) { + timer timer; + registry.view, comp<1>, comp<2>>().each(func); + timer.elapsed(); + }; + + test([](auto &... comp) { + ((comp.x = {}), ...); + }); +} + TEST(Benchmark, IterateFiveComponents1MHalf) { entt::registry registry;