-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- mustache benchmark - entt event with stable pointer
- Loading branch information
Showing
11 changed files
with
278 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
benchmark/benchmarks/entt-extended/EnttStableEventEmitBenchmarkSuite.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include "EnttStableEventEmitBenchmarkSuite.h" | ||
|
||
static ecs::benchmarks::entt::EnttStableEventEmitBenchmarkSuite | ||
benchmark_suite({.add_more_complex_system = ecs::benchmarks::base::add_more_complex_system_t::UseMoreComplexSystems, | ||
.version = ENTT_VERSION}); | ||
|
||
static void BM_TriggerAndUpdateEventsViaDispatcherWithMixedEntities(benchmark::State& state) { | ||
benchmark_suite.BM_TriggerAndUpdateEventsViaDispatcherWithMixedEntities(state); | ||
} | ||
BENCHMARK(BM_TriggerAndUpdateEventsViaDispatcherWithMixedEntities)->Apply(ecs::benchmarks::base::BEDefaultArguments); |
85 changes: 85 additions & 0 deletions
85
benchmark/benchmarks/entt-extended/EnttStableEventEmitBenchmarkSuite.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#ifndef ECS_BENCHMARKS_ENTTSTABLEEVENTBENCHMARK_H_ | ||
#define ECS_BENCHMARKS_ENTTSTABLEEVENTBENCHMARK_H_ | ||
|
||
#include "ExtendedECSBenchmark.h" | ||
#include "entt/StableEnttApplication.h" | ||
#include "entt/entities/HeroMonsterEntityFactory.h" | ||
#include "entt/entities/StableEntityFactory.h" | ||
#include <utility> | ||
|
||
namespace ecs::benchmarks::entt { | ||
|
||
struct Event { | ||
using ComponentOne = ecs::benchmarks::entt::components::StablePositionComponent; | ||
using ComponentTwo = ecs::benchmarks::entt::components::StableVelocityComponent; | ||
|
||
ComponentOne* comp1; | ||
ComponentTwo* comp2; | ||
}; | ||
|
||
struct DummyListener { | ||
public: | ||
DummyListener(::entt::registry& registry, | ||
::entt::dispatcher& dispatcher) : m_registry(registry), m_dispatcher(dispatcher) {} | ||
|
||
void setup() { | ||
m_dispatcher.sink<Event>().connect<&DummyListener::receive>(*this); | ||
} | ||
void teardown() { | ||
m_dispatcher.sink<Event>().disconnect<&DummyListener::receive>(*this); | ||
} | ||
|
||
void receive(Event& event) { | ||
benchmark::DoNotOptimize(*event.comp1); | ||
benchmark::DoNotOptimize(*event.comp2); | ||
//benchmark::DoNotOptimize(event); | ||
} | ||
|
||
private: | ||
::entt::registry& m_registry; | ||
::entt::dispatcher& m_dispatcher; | ||
}; | ||
|
||
class EnttStableEventEmitBenchmarkSuite final | ||
: public ecs::benchmarks::base::ExtendedECSBenchmark<"entt (emit, stable)", StableEnttApplication, entities::StableEntityFactory, | ||
entities::HeroMonsterEntityFactory> { | ||
public: | ||
EnttStableEventEmitBenchmarkSuite() = default; | ||
|
||
explicit EnttStableEventEmitBenchmarkSuite(ecs::benchmarks::base::ESCBenchmarkOptions options) | ||
: ExtendedECSBenchmark(std::move(options)) {} | ||
|
||
void BM_TriggerAndUpdateEventsViaDispatcherWithMixedEntities(benchmark::State& state) { | ||
using ComponentOne = ecs::benchmarks::entt::components::StablePositionComponent; | ||
using ComponentTwo = ecs::benchmarks::entt::components::StableVelocityComponent; | ||
|
||
const auto nentities = static_cast<size_t>(state.range(0)); | ||
StableEnttApplication::Application app(this->m_options.add_more_complex_system); | ||
EntityManager& registry = app.getEntities(); | ||
std::vector<Entity> entities; | ||
const base::ComponentsCounter components_counter = | ||
this->template createEntitiesWithMixedComponents<entities::StableEntityFactory>(registry, nentities, entities); | ||
|
||
::entt::dispatcher dispatcher{}; | ||
DummyListener listener (registry, dispatcher); | ||
|
||
listener.setup(); | ||
|
||
auto view = registry.template view<ComponentOne, ComponentTwo>(); | ||
for (auto _ : state) { | ||
view.each([&](auto /*entity*/, auto& comp1, auto& comp2) { | ||
//dummy_each(comp1, comp2); | ||
dispatcher.trigger<Event>({.comp1 = &comp1, .comp2 = &comp2}); | ||
}); | ||
} | ||
|
||
listener.teardown(); | ||
|
||
this->setCounters(state, entities, components_counter); | ||
//state.counters["events_count"] = static_cast<double>(entities.size()); | ||
} | ||
}; | ||
|
||
} // namespace ecs::benchmarks::entt | ||
|
||
#endif // ECS_BENCHMARKS_ENTTSTABLEEVENTBENCHMARK_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
benchmark/benchmarks/mustache-extended/MustacheEventBenchmarkSuite.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include "MustacheEventBenchmarkSuite.h" | ||
|
||
static ecs::benchmarks::mustache::MustacheEventBenchmarkSuite benchmark_suite({ | ||
.add_more_complex_system = ecs::benchmarks::base::add_more_complex_system_t::UseMoreComplexSystems, | ||
.version = std::nullopt, | ||
}); | ||
|
||
static void BM_PostAndUpdateEventsViaReceiverWithMixedEntities(benchmark::State& state) { | ||
benchmark_suite.BM_PostAndUpdateEventsViaReceiverWithMixedEntities(state); | ||
} | ||
BENCHMARK(BM_PostAndUpdateEventsViaReceiverWithMixedEntities)->Apply(ecs::benchmarks::base::BEDefaultArguments); |
96 changes: 96 additions & 0 deletions
96
benchmark/benchmarks/mustache-extended/MustacheEventBenchmarkSuite.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#ifndef ECS_BENCHMARKS_MUSTACHEEVENTBENCHMARK_H_ | ||
#define ECS_BENCHMARKS_MUSTACHEEVENTBENCHMARK_H_ | ||
|
||
#include "ExtendedECSBenchmark.h" | ||
#include "mustache/MustacheApplication.h" | ||
#include "mustache/entities/EntityFactory.h" | ||
#include "mustache/entities/HeroMonsterEntityFactory.h" | ||
#include "mustache/systems/DataSystem.h" | ||
#include "mustache/systems/MoreComplexSystem.h" | ||
#include "mustache/systems/MovementSystem.h" | ||
#include <utility> | ||
|
||
namespace ecs::benchmarks::mustache { | ||
|
||
struct Event { | ||
::mustache::Entity entity; | ||
}; | ||
|
||
struct DummyEventSystem : public ::mustache::System<DummyEventSystem>, public ::mustache::Receiver<Event> { | ||
void onConfigure(::mustache::World& world, ::mustache::SystemConfig& config) override { | ||
/// FIXME: Error at mustache/ecs/event_manager.hpp:85:22 | ||
//world.events().subscribe<Event>(this); | ||
world.events().subscribe<Event>([&](const Event &e) { | ||
using ComponentOne = ecs::benchmarks::base::components::PositionComponent; | ||
using ComponentTwo = ecs::benchmarks::base::components::VelocityComponent; | ||
benchmark::DoNotOptimize(*world.entities().getComponent<ComponentOne, | ||
::mustache::FunctionSafety::kUnsafe>(e.entity)); | ||
benchmark::DoNotOptimize(*world.entities().getComponent<ComponentTwo, | ||
::mustache::FunctionSafety::kUnsafe>(e.entity)); | ||
}); | ||
} | ||
void onEvent(const Event &e) { | ||
benchmark::DoNotOptimize(e.entity.id()); | ||
} | ||
}; | ||
|
||
class PostEventSystem : public ::mustache::System<PostEventSystem> { | ||
public: | ||
void onUpdate(::mustache::World& world) override { | ||
using ComponentOne = ecs::benchmarks::base::components::PositionComponent; | ||
using ComponentTwo = ecs::benchmarks::base::components::VelocityComponent; | ||
|
||
world.entities().forEach([&](::mustache::Entity entity, const ComponentOne& pos, const ComponentTwo& vel){ | ||
world.events().post(Event{entity}); | ||
}); | ||
} | ||
}; | ||
|
||
|
||
class MustacheEventBenchmarkSuite final | ||
: public ecs::benchmarks::base::ExtendedECSBenchmark<"mustache (event)", MustacheApplication, entities::EntityFactory, | ||
entities::HeroMonsterEntityFactory> { | ||
public: | ||
MustacheEventBenchmarkSuite() = default; | ||
|
||
explicit MustacheEventBenchmarkSuite(ecs::benchmarks::base::ESCBenchmarkOptions options) | ||
: ExtendedECSBenchmark(std::move(options)) {} | ||
|
||
|
||
void BM_PostAndUpdateEventsViaReceiverWithMixedEntities(benchmark::State& state) { | ||
using ComponentOne = ecs::benchmarks::base::components::PositionComponent; | ||
using ComponentTwo = ecs::benchmarks::base::components::VelocityComponent; | ||
|
||
const auto nentities = static_cast<size_t>(state.range(0)); | ||
::mustache::World world; | ||
auto& manager = world.entities(); | ||
std::vector<Entity> entities; | ||
const base::ComponentsCounter components_counter = | ||
this->template createEntitiesWithMixedComponents<entities::EntityFactory>(manager, nentities, entities); | ||
|
||
const auto consumeEvent = [&](const Event &e) { | ||
using ComponentOne = ecs::benchmarks::base::components::PositionComponent; | ||
using ComponentTwo = ecs::benchmarks::base::components::VelocityComponent; | ||
benchmark::DoNotOptimize(*world.entities().getComponent<ComponentOne, | ||
::mustache::FunctionSafety::kUnsafe>(e.entity)); | ||
benchmark::DoNotOptimize(*world.entities().getComponent<ComponentTwo, | ||
::mustache::FunctionSafety::kUnsafe>(e.entity)); | ||
}; | ||
///@FIXME: add onUpdate ? | ||
world.systems().addSystem<PostEventSystem>(); | ||
//world.systems().addSystem<DummyEventSystem>(); | ||
world.events().subscribe<Event>(consumeEvent); | ||
world.init(); | ||
|
||
for (auto _ : state) { | ||
world.update(); | ||
} | ||
|
||
this->setCounters(state, entities, components_counter); | ||
//state.counters["events_count"] = static_cast<double>(entities.size()); | ||
} | ||
}; | ||
|
||
} // namespace ecs::benchmarks::mustache | ||
|
||
#endif // ECS_BENCHMARKS_MUSTACHEEVENTBENCHMARK_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters