|
|
@@ -36,6 +36,13 @@ private:
|
|
|
std::chrono::time_point<std::chrono::system_clock> start;
|
|
|
};
|
|
|
|
|
|
+template<typename Iterable, typename Func>
|
|
|
+void generic(Iterable &&iterable, Func func) {
|
|
|
+ timer timer;
|
|
|
+ std::forward<Iterable>(iterable).each(func);
|
|
|
+ timer.elapsed();
|
|
|
+}
|
|
|
+
|
|
|
template<typename Func>
|
|
|
void pathological(Func func) {
|
|
|
entt::registry registry;
|
|
|
@@ -63,9 +70,9 @@ void pathological(Func func) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- func(registry, [](auto &...comp) {
|
|
|
- ((comp.x = {}), ...);
|
|
|
- });
|
|
|
+ timer timer;
|
|
|
+ func(registry).each([](auto &...comp) { ((comp.x = {}), ...); });
|
|
|
+ timer.elapsed();
|
|
|
}
|
|
|
|
|
|
TEST(Benchmark, Create) {
|
|
|
@@ -100,7 +107,6 @@ TEST(Benchmark, CreateManyAndEmplaceComponents) {
|
|
|
std::cout << "Creating 1000000 entities at once and emplace components" << std::endl;
|
|
|
|
|
|
timer timer;
|
|
|
-
|
|
|
registry.create(entities.begin(), entities.end());
|
|
|
|
|
|
for(const auto entity: entities) {
|
|
|
@@ -127,6 +133,7 @@ TEST(Benchmark, CreateManyWithComponents) {
|
|
|
TEST(Benchmark, Erase) {
|
|
|
entt::registry registry;
|
|
|
std::vector<entt::entity> entities(1000000);
|
|
|
+ auto view = registry.view<int>();
|
|
|
|
|
|
std::cout << "Erasing 1000000 components from their entities" << std::endl;
|
|
|
|
|
|
@@ -135,7 +142,7 @@ TEST(Benchmark, Erase) {
|
|
|
|
|
|
timer timer;
|
|
|
|
|
|
- for(auto entity: registry.view<int>()) {
|
|
|
+ for(auto entity: view) {
|
|
|
registry.erase<int>(entity);
|
|
|
}
|
|
|
|
|
|
@@ -145,6 +152,7 @@ TEST(Benchmark, Erase) {
|
|
|
TEST(Benchmark, EraseMany) {
|
|
|
entt::registry registry;
|
|
|
std::vector<entt::entity> entities(1000000);
|
|
|
+ auto view = registry.view<int>();
|
|
|
|
|
|
std::cout << "Erasing 1000000 components from their entities at once" << std::endl;
|
|
|
|
|
|
@@ -152,7 +160,6 @@ TEST(Benchmark, EraseMany) {
|
|
|
registry.insert<int>(entities.begin(), entities.end());
|
|
|
|
|
|
timer timer;
|
|
|
- auto view = registry.view<int>();
|
|
|
registry.erase<int>(view.begin(), view.end());
|
|
|
timer.elapsed();
|
|
|
}
|
|
|
@@ -160,6 +167,7 @@ TEST(Benchmark, EraseMany) {
|
|
|
TEST(Benchmark, Remove) {
|
|
|
entt::registry registry;
|
|
|
std::vector<entt::entity> entities(1000000);
|
|
|
+ auto view = registry.view<int>();
|
|
|
|
|
|
std::cout << "Removing 1000000 components from their entities" << std::endl;
|
|
|
|
|
|
@@ -168,7 +176,7 @@ TEST(Benchmark, Remove) {
|
|
|
|
|
|
timer timer;
|
|
|
|
|
|
- for(auto entity: registry.view<int>()) {
|
|
|
+ for(auto entity: view) {
|
|
|
registry.remove<int>(entity);
|
|
|
}
|
|
|
|
|
|
@@ -178,6 +186,7 @@ TEST(Benchmark, Remove) {
|
|
|
TEST(Benchmark, RemoveMany) {
|
|
|
entt::registry registry;
|
|
|
std::vector<entt::entity> entities(1000000);
|
|
|
+ auto view = registry.view<int>();
|
|
|
|
|
|
std::cout << "Removing 1000000 components from their entities at once" << std::endl;
|
|
|
|
|
|
@@ -185,7 +194,6 @@ TEST(Benchmark, RemoveMany) {
|
|
|
registry.insert<int>(entities.begin(), entities.end());
|
|
|
|
|
|
timer timer;
|
|
|
- auto view = registry.view<int>();
|
|
|
registry.remove<int>(view.begin(), view.end());
|
|
|
timer.elapsed();
|
|
|
}
|
|
|
@@ -245,6 +253,7 @@ TEST(Benchmark, RecycleMany) {
|
|
|
TEST(Benchmark, Destroy) {
|
|
|
entt::registry registry;
|
|
|
std::vector<entt::entity> entities(1000000);
|
|
|
+ auto view = registry.view<int>();
|
|
|
|
|
|
std::cout << "Destroying 1000000 entities" << std::endl;
|
|
|
|
|
|
@@ -253,7 +262,7 @@ TEST(Benchmark, Destroy) {
|
|
|
|
|
|
timer timer;
|
|
|
|
|
|
- for(auto entity: registry.view<int>()) {
|
|
|
+ for(auto entity: view) {
|
|
|
registry.destroy(entity);
|
|
|
}
|
|
|
|
|
|
@@ -263,6 +272,7 @@ TEST(Benchmark, Destroy) {
|
|
|
TEST(Benchmark, DestroyMany) {
|
|
|
entt::registry registry;
|
|
|
std::vector<entt::entity> entities(1000000);
|
|
|
+ auto view = registry.view<int>();
|
|
|
|
|
|
std::cout << "Destroying 1000000 entities at once" << std::endl;
|
|
|
|
|
|
@@ -270,7 +280,6 @@ TEST(Benchmark, DestroyMany) {
|
|
|
registry.insert<int>(entities.begin(), entities.end());
|
|
|
|
|
|
timer timer;
|
|
|
- auto view = registry.view<int>();
|
|
|
registry.destroy(view.begin(), view.end());
|
|
|
timer.elapsed();
|
|
|
}
|
|
|
@@ -299,13 +308,7 @@ TEST(Benchmark, IterateSingleComponent1M) {
|
|
|
registry.emplace<position>(entity);
|
|
|
}
|
|
|
|
|
|
- auto test = [&](auto func) {
|
|
|
- timer timer;
|
|
|
- registry.view<position>().each(func);
|
|
|
- timer.elapsed();
|
|
|
- };
|
|
|
-
|
|
|
- test([](auto &...comp) {
|
|
|
+ generic(registry.view<position>(), [](auto &...comp) {
|
|
|
((comp.x = {}), ...);
|
|
|
});
|
|
|
}
|
|
|
@@ -320,13 +323,7 @@ TEST(Benchmark, IterateSingleComponentTombstonePolicy1M) {
|
|
|
registry.emplace<stable_position>(entity);
|
|
|
}
|
|
|
|
|
|
- auto test = [&](auto func) {
|
|
|
- timer timer;
|
|
|
- registry.view<stable_position>().each(func);
|
|
|
- timer.elapsed();
|
|
|
- };
|
|
|
-
|
|
|
- test([](auto &...comp) {
|
|
|
+ generic(registry.view<stable_position>(), [](auto &...comp) {
|
|
|
((comp.x = {}), ...);
|
|
|
});
|
|
|
}
|
|
|
@@ -341,15 +338,10 @@ TEST(Benchmark, IterateSingleComponentRuntime1M) {
|
|
|
registry.emplace<position>(entity);
|
|
|
}
|
|
|
|
|
|
- auto test = [&](auto func) {
|
|
|
- entt::id_type types[] = {entt::type_hash<position>::value()};
|
|
|
-
|
|
|
- timer timer;
|
|
|
- registry.runtime_view(std::begin(types), std::end(types)).each(func);
|
|
|
- timer.elapsed();
|
|
|
- };
|
|
|
+ entt::runtime_view view{};
|
|
|
+ view.iterate(registry.storage<position>());
|
|
|
|
|
|
- test([®istry](auto entity) {
|
|
|
+ generic(view, [®istry](auto entity) {
|
|
|
registry.get<position>(entity).x = {};
|
|
|
});
|
|
|
}
|
|
|
@@ -365,13 +357,7 @@ TEST(Benchmark, IterateTwoComponents1M) {
|
|
|
registry.emplace<velocity>(entity);
|
|
|
}
|
|
|
|
|
|
- auto test = [&](auto func) {
|
|
|
- timer timer;
|
|
|
- registry.view<position, velocity>().each(func);
|
|
|
- timer.elapsed();
|
|
|
- };
|
|
|
-
|
|
|
- test([](auto &...comp) {
|
|
|
+ generic(registry.view<position, velocity>(), [](auto &...comp) {
|
|
|
((comp.x = {}), ...);
|
|
|
});
|
|
|
}
|
|
|
@@ -387,13 +373,7 @@ TEST(Benchmark, IterateTombstonePolicyTwoComponentsTombstonePolicy1M) {
|
|
|
registry.emplace<velocity>(entity);
|
|
|
}
|
|
|
|
|
|
- auto test = [&](auto func) {
|
|
|
- timer timer;
|
|
|
- registry.view<stable_position, velocity>().each(func);
|
|
|
- timer.elapsed();
|
|
|
- };
|
|
|
-
|
|
|
- test([](auto &...comp) {
|
|
|
+ generic(registry.view<stable_position, velocity>(), [](auto &...comp) {
|
|
|
((comp.x = {}), ...);
|
|
|
});
|
|
|
}
|
|
|
@@ -412,13 +392,7 @@ TEST(Benchmark, IterateTwoComponents1MHalf) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- auto test = [&](auto func) {
|
|
|
- timer timer;
|
|
|
- registry.view<position, velocity>().each(func);
|
|
|
- timer.elapsed();
|
|
|
- };
|
|
|
-
|
|
|
- test([](auto &...comp) {
|
|
|
+ generic(registry.view<position, velocity>(), [](auto &...comp) {
|
|
|
((comp.x = {}), ...);
|
|
|
});
|
|
|
}
|
|
|
@@ -437,20 +411,13 @@ TEST(Benchmark, IterateTwoComponents1MOne) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- auto test = [&](auto func) {
|
|
|
- timer timer;
|
|
|
- registry.view<position, velocity>().each(func);
|
|
|
- timer.elapsed();
|
|
|
- };
|
|
|
-
|
|
|
- test([](auto &...comp) {
|
|
|
+ generic(registry.view<position, velocity>(), [](auto &...comp) {
|
|
|
((comp.x = {}), ...);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
TEST(Benchmark, IterateTwoComponentsNonOwningGroup1M) {
|
|
|
entt::registry registry;
|
|
|
- const auto group = registry.group<>(entt::get<position, velocity>);
|
|
|
|
|
|
std::cout << "Iterating over 1000000 entities, two components, non owning group" << std::endl;
|
|
|
|
|
|
@@ -460,20 +427,13 @@ TEST(Benchmark, IterateTwoComponentsNonOwningGroup1M) {
|
|
|
registry.emplace<velocity>(entity);
|
|
|
}
|
|
|
|
|
|
- auto test = [&](auto func) {
|
|
|
- timer timer;
|
|
|
- group.each(func);
|
|
|
- timer.elapsed();
|
|
|
- };
|
|
|
-
|
|
|
- test([](auto &...comp) {
|
|
|
+ generic(registry.group<>(entt::get<position, velocity>), [](auto &...comp) {
|
|
|
((comp.x = {}), ...);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
TEST(Benchmark, IterateTwoComponentsFullOwningGroup1M) {
|
|
|
entt::registry registry;
|
|
|
- const auto group = registry.group<position, velocity>();
|
|
|
|
|
|
std::cout << "Iterating over 1000000 entities, two components, full owning group" << std::endl;
|
|
|
|
|
|
@@ -483,20 +443,13 @@ TEST(Benchmark, IterateTwoComponentsFullOwningGroup1M) {
|
|
|
registry.emplace<velocity>(entity);
|
|
|
}
|
|
|
|
|
|
- auto test = [&](auto func) {
|
|
|
- timer timer;
|
|
|
- group.each(func);
|
|
|
- timer.elapsed();
|
|
|
- };
|
|
|
-
|
|
|
- test([](auto &...comp) {
|
|
|
+ generic(registry.group<position, velocity>(), [](auto &...comp) {
|
|
|
((comp.x = {}), ...);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
TEST(Benchmark, IterateTwoComponentsPartialOwningGroup1M) {
|
|
|
entt::registry registry;
|
|
|
- const auto group = registry.group<position>(entt::get<velocity>);
|
|
|
|
|
|
std::cout << "Iterating over 1000000 entities, two components, partial owning group" << std::endl;
|
|
|
|
|
|
@@ -506,13 +459,7 @@ TEST(Benchmark, IterateTwoComponentsPartialOwningGroup1M) {
|
|
|
registry.emplace<velocity>(entity);
|
|
|
}
|
|
|
|
|
|
- auto test = [&](auto func) {
|
|
|
- timer timer;
|
|
|
- group.each(func);
|
|
|
- timer.elapsed();
|
|
|
- };
|
|
|
-
|
|
|
- test([](auto &...comp) {
|
|
|
+ generic(registry.group<position>(entt::get<velocity>), [](auto &...comp) {
|
|
|
((comp.x = {}), ...);
|
|
|
});
|
|
|
}
|
|
|
@@ -528,17 +475,11 @@ TEST(Benchmark, IterateTwoComponentsRuntime1M) {
|
|
|
registry.emplace<velocity>(entity);
|
|
|
}
|
|
|
|
|
|
- auto test = [&](auto func) {
|
|
|
- entt::id_type types[] = {
|
|
|
- entt::type_hash<position>::value(),
|
|
|
- entt::type_hash<velocity>::value()};
|
|
|
-
|
|
|
- timer timer;
|
|
|
- registry.runtime_view(std::begin(types), std::end(types)).each(func);
|
|
|
- timer.elapsed();
|
|
|
- };
|
|
|
+ entt::runtime_view view{};
|
|
|
+ view.iterate(registry.storage<position>())
|
|
|
+ .iterate(registry.storage<velocity>());
|
|
|
|
|
|
- test([®istry](auto entity) {
|
|
|
+ generic(view, [®istry](auto entity) {
|
|
|
registry.get<position>(entity).x = {};
|
|
|
registry.get<velocity>(entity).x = {};
|
|
|
});
|
|
|
@@ -558,17 +499,11 @@ TEST(Benchmark, IterateTwoComponentsRuntime1MHalf) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- auto test = [&](auto func) {
|
|
|
- entt::id_type types[] = {
|
|
|
- entt::type_hash<position>::value(),
|
|
|
- entt::type_hash<velocity>::value()};
|
|
|
-
|
|
|
- timer timer;
|
|
|
- registry.runtime_view(std::begin(types), std::end(types)).each(func);
|
|
|
- timer.elapsed();
|
|
|
- };
|
|
|
+ entt::runtime_view view{};
|
|
|
+ view.iterate(registry.storage<position>())
|
|
|
+ .iterate(registry.storage<velocity>());
|
|
|
|
|
|
- test([®istry](auto entity) {
|
|
|
+ generic(view, [®istry](auto entity) {
|
|
|
registry.get<position>(entity).x = {};
|
|
|
registry.get<velocity>(entity).x = {};
|
|
|
});
|
|
|
@@ -588,17 +523,11 @@ TEST(Benchmark, IterateTwoComponentsRuntime1MOne) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- auto test = [&](auto func) {
|
|
|
- entt::id_type types[] = {
|
|
|
- entt::type_hash<position>::value(),
|
|
|
- entt::type_hash<velocity>::value()};
|
|
|
+ entt::runtime_view view{};
|
|
|
+ view.iterate(registry.storage<position>())
|
|
|
+ .iterate(registry.storage<velocity>());
|
|
|
|
|
|
- timer timer;
|
|
|
- registry.runtime_view(std::begin(types), std::end(types)).each(func);
|
|
|
- timer.elapsed();
|
|
|
- };
|
|
|
-
|
|
|
- test([®istry](auto entity) {
|
|
|
+ generic(view, [®istry](auto entity) {
|
|
|
registry.get<position>(entity).x = {};
|
|
|
registry.get<velocity>(entity).x = {};
|
|
|
});
|
|
|
@@ -616,13 +545,7 @@ TEST(Benchmark, IterateThreeComponents1M) {
|
|
|
registry.emplace<comp<0>>(entity);
|
|
|
}
|
|
|
|
|
|
- auto test = [&](auto func) {
|
|
|
- timer timer;
|
|
|
- registry.view<position, velocity, comp<0>>().each(func);
|
|
|
- timer.elapsed();
|
|
|
- };
|
|
|
-
|
|
|
- test([](auto &...comp) {
|
|
|
+ generic(registry.view<position, velocity, comp<0>>(), [](auto &...comp) {
|
|
|
((comp.x = {}), ...);
|
|
|
});
|
|
|
}
|
|
|
@@ -639,13 +562,7 @@ TEST(Benchmark, IterateThreeComponentsTombstonePolicy1M) {
|
|
|
registry.emplace<comp<0>>(entity);
|
|
|
}
|
|
|
|
|
|
- auto test = [&](auto func) {
|
|
|
- timer timer;
|
|
|
- registry.view<stable_position, velocity, comp<0>>().each(func);
|
|
|
- timer.elapsed();
|
|
|
- };
|
|
|
-
|
|
|
- test([](auto &...comp) {
|
|
|
+ generic(registry.view<stable_position, velocity, comp<0>>(), [](auto &...comp) {
|
|
|
((comp.x = {}), ...);
|
|
|
});
|
|
|
}
|
|
|
@@ -665,13 +582,7 @@ TEST(Benchmark, IterateThreeComponents1MHalf) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- auto test = [&](auto func) {
|
|
|
- timer timer;
|
|
|
- registry.view<position, velocity, comp<0>>().each(func);
|
|
|
- timer.elapsed();
|
|
|
- };
|
|
|
-
|
|
|
- test([](auto &...comp) {
|
|
|
+ generic(registry.view<position, velocity, comp<0>>(), [](auto &...comp) {
|
|
|
((comp.x = {}), ...);
|
|
|
});
|
|
|
}
|
|
|
@@ -691,20 +602,13 @@ TEST(Benchmark, IterateThreeComponents1MOne) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- auto test = [&](auto func) {
|
|
|
- timer timer;
|
|
|
- registry.view<position, velocity, comp<0>>().each(func);
|
|
|
- timer.elapsed();
|
|
|
- };
|
|
|
-
|
|
|
- test([](auto &...comp) {
|
|
|
+ generic(registry.view<position, velocity, comp<0>>(), [](auto &...comp) {
|
|
|
((comp.x = {}), ...);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
TEST(Benchmark, IterateThreeComponentsNonOwningGroup1M) {
|
|
|
entt::registry registry;
|
|
|
- const auto group = registry.group<>(entt::get<position, velocity, comp<0>>);
|
|
|
|
|
|
std::cout << "Iterating over 1000000 entities, three components, non owning group" << std::endl;
|
|
|
|
|
|
@@ -715,20 +619,13 @@ TEST(Benchmark, IterateThreeComponentsNonOwningGroup1M) {
|
|
|
registry.emplace<comp<0>>(entity);
|
|
|
}
|
|
|
|
|
|
- auto test = [&](auto func) {
|
|
|
- timer timer;
|
|
|
- group.each(func);
|
|
|
- timer.elapsed();
|
|
|
- };
|
|
|
-
|
|
|
- test([](auto &...comp) {
|
|
|
+ generic(registry.group<>(entt::get<position, velocity, comp<0>>), [](auto &...comp) {
|
|
|
((comp.x = {}), ...);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
TEST(Benchmark, IterateThreeComponentsFullOwningGroup1M) {
|
|
|
entt::registry registry;
|
|
|
- const auto group = registry.group<position, velocity, comp<0>>();
|
|
|
|
|
|
std::cout << "Iterating over 1000000 entities, three components, full owning group" << std::endl;
|
|
|
|
|
|
@@ -739,20 +636,13 @@ TEST(Benchmark, IterateThreeComponentsFullOwningGroup1M) {
|
|
|
registry.emplace<comp<0>>(entity);
|
|
|
}
|
|
|
|
|
|
- auto test = [&](auto func) {
|
|
|
- timer timer;
|
|
|
- group.each(func);
|
|
|
- timer.elapsed();
|
|
|
- };
|
|
|
-
|
|
|
- test([](auto &...comp) {
|
|
|
+ generic(registry.group<position, velocity, comp<0>>(), [](auto &...comp) {
|
|
|
((comp.x = {}), ...);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
TEST(Benchmark, IterateThreeComponentsPartialOwningGroup1M) {
|
|
|
entt::registry registry;
|
|
|
- const auto group = registry.group<position, velocity>(entt::get<comp<0>>);
|
|
|
|
|
|
std::cout << "Iterating over 1000000 entities, three components, partial owning group" << std::endl;
|
|
|
|
|
|
@@ -763,13 +653,7 @@ TEST(Benchmark, IterateThreeComponentsPartialOwningGroup1M) {
|
|
|
registry.emplace<comp<0>>(entity);
|
|
|
}
|
|
|
|
|
|
- auto test = [&](auto func) {
|
|
|
- timer timer;
|
|
|
- group.each(func);
|
|
|
- timer.elapsed();
|
|
|
- };
|
|
|
-
|
|
|
- test([](auto &...comp) {
|
|
|
+ generic(registry.group<position, velocity>(entt::get<comp<0>>), [](auto &...comp) {
|
|
|
((comp.x = {}), ...);
|
|
|
});
|
|
|
}
|
|
|
@@ -786,18 +670,12 @@ TEST(Benchmark, IterateThreeComponentsRuntime1M) {
|
|
|
registry.emplace<comp<0>>(entity);
|
|
|
}
|
|
|
|
|
|
- auto test = [&](auto func) {
|
|
|
- entt::id_type types[] = {
|
|
|
- entt::type_hash<position>::value(),
|
|
|
- entt::type_hash<velocity>::value(),
|
|
|
- entt::type_hash<comp<0>>::value()};
|
|
|
-
|
|
|
- timer timer;
|
|
|
- registry.runtime_view(std::begin(types), std::end(types)).each(func);
|
|
|
- timer.elapsed();
|
|
|
- };
|
|
|
+ entt::runtime_view view{};
|
|
|
+ view.iterate(registry.storage<position>())
|
|
|
+ .iterate(registry.storage<velocity>())
|
|
|
+ .iterate(registry.storage<comp<0>>());
|
|
|
|
|
|
- test([®istry](auto entity) {
|
|
|
+ generic(view, [®istry](auto entity) {
|
|
|
registry.get<position>(entity).x = {};
|
|
|
registry.get<velocity>(entity).x = {};
|
|
|
registry.get<comp<0>>(entity).x = {};
|
|
|
@@ -819,18 +697,12 @@ TEST(Benchmark, IterateThreeComponentsRuntime1MHalf) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- auto test = [&](auto func) {
|
|
|
- entt::id_type types[] = {
|
|
|
- entt::type_hash<position>::value(),
|
|
|
- entt::type_hash<velocity>::value(),
|
|
|
- entt::type_hash<comp<0>>::value()};
|
|
|
+ entt::runtime_view view{};
|
|
|
+ view.iterate(registry.storage<position>())
|
|
|
+ .iterate(registry.storage<velocity>())
|
|
|
+ .iterate(registry.storage<comp<0>>());
|
|
|
|
|
|
- timer timer;
|
|
|
- registry.runtime_view(std::begin(types), std::end(types)).each(func);
|
|
|
- timer.elapsed();
|
|
|
- };
|
|
|
-
|
|
|
- test([®istry](auto entity) {
|
|
|
+ generic(view, [®istry](auto entity) {
|
|
|
registry.get<position>(entity).x = {};
|
|
|
registry.get<velocity>(entity).x = {};
|
|
|
registry.get<comp<0>>(entity).x = {};
|
|
|
@@ -852,18 +724,12 @@ TEST(Benchmark, IterateThreeComponentsRuntime1MOne) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- auto test = [&](auto func) {
|
|
|
- entt::id_type types[] = {
|
|
|
- entt::type_hash<position>::value(),
|
|
|
- entt::type_hash<velocity>::value(),
|
|
|
- entt::type_hash<comp<0>>::value()};
|
|
|
-
|
|
|
- timer timer;
|
|
|
- registry.runtime_view(std::begin(types), std::end(types)).each(func);
|
|
|
- timer.elapsed();
|
|
|
- };
|
|
|
+ entt::runtime_view view{};
|
|
|
+ view.iterate(registry.storage<position>())
|
|
|
+ .iterate(registry.storage<velocity>())
|
|
|
+ .iterate(registry.storage<comp<0>>());
|
|
|
|
|
|
- test([®istry](auto entity) {
|
|
|
+ generic(view, [®istry](auto entity) {
|
|
|
registry.get<position>(entity).x = {};
|
|
|
registry.get<velocity>(entity).x = {};
|
|
|
registry.get<comp<0>>(entity).x = {};
|
|
|
@@ -884,13 +750,7 @@ TEST(Benchmark, IterateFiveComponents1M) {
|
|
|
registry.emplace<comp<2>>(entity);
|
|
|
}
|
|
|
|
|
|
- auto test = [&](auto func) {
|
|
|
- timer timer;
|
|
|
- registry.view<position, velocity, comp<0>, comp<1>, comp<2>>().each(func);
|
|
|
- timer.elapsed();
|
|
|
- };
|
|
|
-
|
|
|
- test([](auto &...comp) {
|
|
|
+ generic(registry.view<position, velocity, comp<0>, comp<1>, comp<2>>(), [](auto &...comp) {
|
|
|
((comp.x = {}), ...);
|
|
|
});
|
|
|
}
|
|
|
@@ -909,13 +769,7 @@ TEST(Benchmark, IterateFiveComponentsTombstonePolicy1M) {
|
|
|
registry.emplace<comp<2>>(entity);
|
|
|
}
|
|
|
|
|
|
- auto test = [&](auto func) {
|
|
|
- timer timer;
|
|
|
- registry.view<stable_position, velocity, comp<0>, comp<1>, comp<2>>().each(func);
|
|
|
- timer.elapsed();
|
|
|
- };
|
|
|
-
|
|
|
- test([](auto &...comp) {
|
|
|
+ generic(registry.view<stable_position, velocity, comp<0>, comp<1>, comp<2>>(), [](auto &...comp) {
|
|
|
((comp.x = {}), ...);
|
|
|
});
|
|
|
}
|
|
|
@@ -937,13 +791,7 @@ TEST(Benchmark, IterateFiveComponents1MHalf) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- auto test = [&](auto func) {
|
|
|
- timer timer;
|
|
|
- registry.view<position, velocity, comp<0>, comp<1>, comp<2>>().each(func);
|
|
|
- timer.elapsed();
|
|
|
- };
|
|
|
-
|
|
|
- test([](auto &...comp) {
|
|
|
+ generic(registry.view<position, velocity, comp<0>, comp<1>, comp<2>>(), [](auto &...comp) {
|
|
|
((comp.x = {}), ...);
|
|
|
});
|
|
|
}
|
|
|
@@ -965,20 +813,13 @@ TEST(Benchmark, IterateFiveComponents1MOne) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- auto test = [&](auto func) {
|
|
|
- timer timer;
|
|
|
- registry.view<position, velocity, comp<0>, comp<1>, comp<2>>().each(func);
|
|
|
- timer.elapsed();
|
|
|
- };
|
|
|
-
|
|
|
- test([](auto &...comp) {
|
|
|
+ generic(registry.view<position, velocity, comp<0>, comp<1>, comp<2>>(), [](auto &...comp) {
|
|
|
((comp.x = {}), ...);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
TEST(Benchmark, IterateFiveComponentsNonOwningGroup1M) {
|
|
|
entt::registry registry;
|
|
|
- const auto group = registry.group<>(entt::get<position, velocity, comp<0>, comp<1>, comp<2>>);
|
|
|
|
|
|
std::cout << "Iterating over 1000000 entities, five components, non owning group" << std::endl;
|
|
|
|
|
|
@@ -991,20 +832,13 @@ TEST(Benchmark, IterateFiveComponentsNonOwningGroup1M) {
|
|
|
registry.emplace<comp<2>>(entity);
|
|
|
}
|
|
|
|
|
|
- auto test = [&](auto func) {
|
|
|
- timer timer;
|
|
|
- group.each(func);
|
|
|
- timer.elapsed();
|
|
|
- };
|
|
|
-
|
|
|
- test([](auto &...comp) {
|
|
|
+ generic(registry.group<>(entt::get<position, velocity, comp<0>, comp<1>, comp<2>>), [](auto &...comp) {
|
|
|
((comp.x = {}), ...);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
TEST(Benchmark, IterateFiveComponentsFullOwningGroup1M) {
|
|
|
entt::registry registry;
|
|
|
- const auto group = registry.group<position, velocity, comp<0>, comp<1>, comp<2>>();
|
|
|
|
|
|
std::cout << "Iterating over 1000000 entities, five components, full owning group" << std::endl;
|
|
|
|
|
|
@@ -1017,20 +851,13 @@ TEST(Benchmark, IterateFiveComponentsFullOwningGroup1M) {
|
|
|
registry.emplace<comp<2>>(entity);
|
|
|
}
|
|
|
|
|
|
- auto test = [&](auto func) {
|
|
|
- timer timer;
|
|
|
- group.each(func);
|
|
|
- timer.elapsed();
|
|
|
- };
|
|
|
-
|
|
|
- test([](auto &...comp) {
|
|
|
+ generic(registry.group<position, velocity, comp<0>, comp<1>, comp<2>>(), [](auto &...comp) {
|
|
|
((comp.x = {}), ...);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
TEST(Benchmark, IterateFiveComponentsPartialFourOfFiveOwningGroup1M) {
|
|
|
entt::registry registry;
|
|
|
- const auto group = registry.group<position, velocity, comp<0>, comp<1>>(entt::get<comp<2>>);
|
|
|
|
|
|
std::cout << "Iterating over 1000000 entities, five components, partial (4 of 5) owning group" << std::endl;
|
|
|
|
|
|
@@ -1043,20 +870,13 @@ TEST(Benchmark, IterateFiveComponentsPartialFourOfFiveOwningGroup1M) {
|
|
|
registry.emplace<comp<2>>(entity);
|
|
|
}
|
|
|
|
|
|
- auto test = [&](auto func) {
|
|
|
- timer timer;
|
|
|
- group.each(func);
|
|
|
- timer.elapsed();
|
|
|
- };
|
|
|
-
|
|
|
- test([](auto &...comp) {
|
|
|
+ generic(registry.group<position, velocity, comp<0>, comp<1>>(entt::get<comp<2>>), [](auto &...comp) {
|
|
|
((comp.x = {}), ...);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
TEST(Benchmark, IterateFiveComponentsPartialThreeOfFiveOwningGroup1M) {
|
|
|
entt::registry registry;
|
|
|
- const auto group = registry.group<position, velocity, comp<0>>(entt::get<comp<1>, comp<2>>);
|
|
|
|
|
|
std::cout << "Iterating over 1000000 entities, five components, partial (3 of 5) owning group" << std::endl;
|
|
|
|
|
|
@@ -1069,13 +889,7 @@ TEST(Benchmark, IterateFiveComponentsPartialThreeOfFiveOwningGroup1M) {
|
|
|
registry.emplace<comp<2>>(entity);
|
|
|
}
|
|
|
|
|
|
- auto test = [&](auto func) {
|
|
|
- timer timer;
|
|
|
- group.each(func);
|
|
|
- timer.elapsed();
|
|
|
- };
|
|
|
-
|
|
|
- test([](auto &...comp) {
|
|
|
+ generic(registry.group<position, velocity, comp<0>>(entt::get<comp<1>, comp<2>>), [](auto &...comp) {
|
|
|
((comp.x = {}), ...);
|
|
|
});
|
|
|
}
|
|
|
@@ -1094,20 +908,14 @@ TEST(Benchmark, IterateFiveComponentsRuntime1M) {
|
|
|
registry.emplace<comp<2>>(entity);
|
|
|
}
|
|
|
|
|
|
- auto test = [&](auto func) {
|
|
|
- entt::id_type types[] = {
|
|
|
- entt::type_hash<position>::value(),
|
|
|
- entt::type_hash<velocity>::value(),
|
|
|
- entt::type_hash<comp<0>>::value(),
|
|
|
- entt::type_hash<comp<1>>::value(),
|
|
|
- entt::type_hash<comp<2>>::value()};
|
|
|
-
|
|
|
- timer timer;
|
|
|
- registry.runtime_view(std::begin(types), std::end(types)).each(func);
|
|
|
- timer.elapsed();
|
|
|
- };
|
|
|
+ entt::runtime_view view{};
|
|
|
+ view.iterate(registry.storage<position>())
|
|
|
+ .iterate(registry.storage<velocity>())
|
|
|
+ .iterate(registry.storage<comp<0>>())
|
|
|
+ .iterate(registry.storage<comp<1>>())
|
|
|
+ .iterate(registry.storage<comp<2>>());
|
|
|
|
|
|
- test([®istry](auto entity) {
|
|
|
+ generic(view, [®istry](auto entity) {
|
|
|
registry.get<position>(entity).x = {};
|
|
|
registry.get<velocity>(entity).x = {};
|
|
|
registry.get<comp<0>>(entity).x = {};
|
|
|
@@ -1133,20 +941,14 @@ TEST(Benchmark, IterateFiveComponentsRuntime1MHalf) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- auto test = [&](auto func) {
|
|
|
- entt::id_type types[] = {
|
|
|
- entt::type_hash<position>::value(),
|
|
|
- entt::type_hash<velocity>::value(),
|
|
|
- entt::type_hash<comp<0>>::value(),
|
|
|
- entt::type_hash<comp<1>>::value(),
|
|
|
- entt::type_hash<comp<2>>::value()};
|
|
|
+ entt::runtime_view view{};
|
|
|
+ view.iterate(registry.storage<position>())
|
|
|
+ .iterate(registry.storage<velocity>())
|
|
|
+ .iterate(registry.storage<comp<0>>())
|
|
|
+ .iterate(registry.storage<comp<1>>())
|
|
|
+ .iterate(registry.storage<comp<2>>());
|
|
|
|
|
|
- timer timer;
|
|
|
- registry.runtime_view(std::begin(types), std::end(types)).each(func);
|
|
|
- timer.elapsed();
|
|
|
- };
|
|
|
-
|
|
|
- test([®istry](auto entity) {
|
|
|
+ generic(view, [®istry](auto entity) {
|
|
|
registry.get<position>(entity).x = {};
|
|
|
registry.get<velocity>(entity).x = {};
|
|
|
registry.get<comp<0>>(entity).x = {};
|
|
|
@@ -1172,20 +974,14 @@ TEST(Benchmark, IterateFiveComponentsRuntime1MOne) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- auto test = [&](auto func) {
|
|
|
- entt::id_type types[] = {
|
|
|
- entt::type_hash<position>::value(),
|
|
|
- entt::type_hash<velocity>::value(),
|
|
|
- entt::type_hash<comp<0>>::value(),
|
|
|
- entt::type_hash<comp<1>>::value(),
|
|
|
- entt::type_hash<comp<2>>::value()};
|
|
|
-
|
|
|
- timer timer;
|
|
|
- registry.runtime_view(std::begin(types), std::end(types)).each(func);
|
|
|
- timer.elapsed();
|
|
|
- };
|
|
|
+ entt::runtime_view view{};
|
|
|
+ view.iterate(registry.storage<position>())
|
|
|
+ .iterate(registry.storage<velocity>())
|
|
|
+ .iterate(registry.storage<comp<0>>())
|
|
|
+ .iterate(registry.storage<comp<1>>())
|
|
|
+ .iterate(registry.storage<comp<2>>());
|
|
|
|
|
|
- test([®istry](auto entity) {
|
|
|
+ generic(view, [®istry](auto entity) {
|
|
|
registry.get<position>(entity).x = {};
|
|
|
registry.get<velocity>(entity).x = {};
|
|
|
registry.get<comp<0>>(entity).x = {};
|
|
|
@@ -1196,48 +992,22 @@ TEST(Benchmark, IterateFiveComponentsRuntime1MOne) {
|
|
|
|
|
|
TEST(Benchmark, IteratePathological) {
|
|
|
std::cout << "Pathological case" << std::endl;
|
|
|
-
|
|
|
- pathological([](auto ®istry, auto func) {
|
|
|
- timer timer;
|
|
|
- registry.template view<position, velocity, comp<0>>().each(func);
|
|
|
- timer.elapsed();
|
|
|
- });
|
|
|
+ pathological([](auto ®istry) { return registry.template view<position, velocity, comp<0>>(); });
|
|
|
}
|
|
|
|
|
|
TEST(Benchmark, IteratePathologicalNonOwningGroup) {
|
|
|
std::cout << "Pathological case (non-owning group)" << std::endl;
|
|
|
-
|
|
|
- pathological([](auto ®istry, auto func) {
|
|
|
- auto group = registry.template group<>(entt::get<position, velocity, comp<0>>);
|
|
|
-
|
|
|
- timer timer;
|
|
|
- group.each(func);
|
|
|
- timer.elapsed();
|
|
|
- });
|
|
|
+ pathological([](auto ®istry) { return registry.template group<>(entt::get<position, velocity, comp<0>>); });
|
|
|
}
|
|
|
|
|
|
TEST(Benchmark, IteratePathologicalFullOwningGroup) {
|
|
|
std::cout << "Pathological case (full-owning group)" << std::endl;
|
|
|
-
|
|
|
- pathological([](auto ®istry, auto func) {
|
|
|
- auto group = registry.template group<position, velocity, comp<0>>();
|
|
|
-
|
|
|
- timer timer;
|
|
|
- group.each(func);
|
|
|
- timer.elapsed();
|
|
|
- });
|
|
|
+ pathological([](auto ®istry) { return registry.template group<position, velocity, comp<0>>(); });
|
|
|
}
|
|
|
|
|
|
TEST(Benchmark, IteratePathologicalPartialOwningGroup) {
|
|
|
std::cout << "Pathological case (partial-owning group)" << std::endl;
|
|
|
-
|
|
|
- pathological([](auto ®istry, auto func) {
|
|
|
- auto group = registry.template group<position, velocity>(entt::get<comp<0>>);
|
|
|
-
|
|
|
- timer timer;
|
|
|
- group.each(func);
|
|
|
- timer.elapsed();
|
|
|
- });
|
|
|
+ pathological([](auto ®istry) { return registry.template group<position, velocity>(entt::get<comp<0>>); });
|
|
|
}
|
|
|
|
|
|
TEST(Benchmark, SortSingle) {
|
|
|
@@ -1251,9 +1021,7 @@ TEST(Benchmark, SortSingle) {
|
|
|
}
|
|
|
|
|
|
timer timer;
|
|
|
-
|
|
|
registry.sort<position>([](const auto &lhs, const auto &rhs) { return lhs.x < rhs.x && lhs.y < rhs.y; });
|
|
|
-
|
|
|
timer.elapsed();
|
|
|
}
|
|
|
|
|
|
@@ -1271,9 +1039,7 @@ TEST(Benchmark, SortMulti) {
|
|
|
registry.sort<position>([](const auto &lhs, const auto &rhs) { return lhs.x < rhs.x && lhs.y < rhs.y; });
|
|
|
|
|
|
timer timer;
|
|
|
-
|
|
|
registry.sort<velocity, position>();
|
|
|
-
|
|
|
timer.elapsed();
|
|
|
}
|
|
|
|
|
|
@@ -1299,9 +1065,7 @@ TEST(Benchmark, AlmostSortedStdSort) {
|
|
|
}
|
|
|
|
|
|
timer timer;
|
|
|
-
|
|
|
registry.sort<position>([](const auto &lhs, const auto &rhs) { return lhs.x > rhs.x && lhs.y > rhs.y; });
|
|
|
-
|
|
|
timer.elapsed();
|
|
|
}
|
|
|
|
|
|
@@ -1327,8 +1091,6 @@ TEST(Benchmark, AlmostSortedInsertionSort) {
|
|
|
}
|
|
|
|
|
|
timer timer;
|
|
|
-
|
|
|
registry.sort<position>([](const auto &lhs, const auto &rhs) { return lhs.x > rhs.x && lhs.y > rhs.y; }, entt::insertion_sort{});
|
|
|
-
|
|
|
timer.elapsed();
|
|
|
}
|