diff options
author | Alec Thomas <alec@swapoff.org> | 2014-10-10 15:49:11 +1100 |
---|---|---|
committer | Alec Thomas <alec@swapoff.org> | 2014-10-10 15:49:11 +1100 |
commit | 1e65256445d2088145d4f5fa1b418c6529abfb3c (patch) | |
tree | a7eece9380a1250747ce5ffca31d4e98792495b6 | |
parent | 585a2835442cef94f1ca0c2290fb17f660ee1641 (diff) |
Add benchmark for unpacking two components.
-rw-r--r-- | entityx/Benchmarks_test.cc | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/entityx/Benchmarks_test.cc b/entityx/Benchmarks_test.cc index e234340..2cb067a 100644 --- a/entityx/Benchmarks_test.cc +++ b/entityx/Benchmarks_test.cc @@ -31,6 +31,10 @@ struct Position : public Component<Position> { }; +struct Direction : public Component<Direction> { +}; + + struct BenchmarkFixture { BenchmarkFixture() : em(ev) {} @@ -116,8 +120,25 @@ TEST_CASE_METHOD(BenchmarkFixture, "TestEntityIteration") { cout << "iterating over " << count << " entities, unpacking one component" << endl; ComponentHandle<Position> position; - for (auto e : em.entities_with_components<Position>(position)) { + for (auto e : em.entities_with_components(position)) { + (void)e; + } +} + +TEST_CASE_METHOD(BenchmarkFixture, "TestEntityIterationUnpackTwo") { + int count = 10000000; + for (int i = 0; i < count; i++) { + auto e = em.create(); + e.assign<Position>(); + e.assign<Direction>(); + } + + AutoTimer t; + cout << "iterating over " << count << " entities, unpacking two components" << endl; + + ComponentHandle<Position> position; + ComponentHandle<Direction> direction; + for (auto e : em.entities_with_components(position, direction)) { (void)e; - position.valid(); } } |