From 1e65256445d2088145d4f5fa1b418c6529abfb3c Mon Sep 17 00:00:00 2001 From: Alec Thomas Date: Fri, 10 Oct 2014 15:49:11 +1100 Subject: Add benchmark for unpacking two components. --- entityx/Benchmarks_test.cc | 25 +++++++++++++++++++++++-- 1 file 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 { }; +struct Direction : public Component { +}; + + 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; - for (auto e : em.entities_with_components(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(); + e.assign(); + } + + AutoTimer t; + cout << "iterating over " << count << " entities, unpacking two components" << endl; + + ComponentHandle position; + ComponentHandle direction; + for (auto e : em.entities_with_components(position, direction)) { (void)e; - position.valid(); } } -- cgit v1.2.3