]> code.bitgloo.com Git - clyne/entityx.git/commitdiff
Add benchmark for unpacking two components.
authorAlec Thomas <alec@swapoff.org>
Fri, 10 Oct 2014 04:49:11 +0000 (15:49 +1100)
committerAlec Thomas <alec@swapoff.org>
Fri, 10 Oct 2014 04:49:11 +0000 (15:49 +1100)
entityx/Benchmarks_test.cc

index e234340653039aea91568690dc60d51031b6cb55..2cb067aed4ab39c412f743d0a3eb0c0be12a36ee 100644 (file)
@@ -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();
   }
 }