aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlec Thomas <alec@swapoff.org>2013-11-29 12:47:35 -0500
committerAlec Thomas <alec@swapoff.org>2013-11-29 12:47:35 -0500
commitb92144502f6d7e779aa7f1e7b657aee2314abf57 (patch)
treeee2e671a010a155faa33548fc77d356ac44a1a9a
parent130837fd4d56f84c5d75401ec65938b7ae196c81 (diff)
Make benchmarks work.
-rw-r--r--entityx/Benchmarks_test.cc24
-rw-r--r--entityx/help/NonCopyable.h15
-rw-r--r--entityx/help/Timer.cc24
-rw-r--r--entityx/help/Timer.h19
4 files changed, 42 insertions, 40 deletions
diff --git a/entityx/Benchmarks_test.cc b/entityx/Benchmarks_test.cc
index f469c37..100defd 100644
--- a/entityx/Benchmarks_test.cc
+++ b/entityx/Benchmarks_test.cc
@@ -1,12 +1,22 @@
#include <iostream>
#include <vector>
-#include <gtest/gtest.h>
-#include <boost/timer/timer.hpp>
+#include "gtest/gtest.h"
+#include "entityx/help/Timer.h"
#include "entityx/Entity.h"
using namespace std;
using namespace entityx;
+
+struct AutoTimer {
+ ~AutoTimer() {
+ cout << timer_.elapsed() << " seconds elapsed" << endl;
+ }
+
+private:
+ entityx::help::Timer timer_;
+};
+
class BenchmarksTest : public ::testing::Test {
protected:
BenchmarksTest() : ev(EventManager::make()), em(EntityManager::make(ev)) {}
@@ -17,7 +27,7 @@ protected:
TEST_F(BenchmarksTest, TestCreateEntities) {
- boost::timer::auto_cpu_timer t;
+ AutoTimer t;
uint64_t count = 10000000L;
cout << "creating " << count << " entities" << endl;
@@ -35,7 +45,7 @@ TEST_F(BenchmarksTest, TestDestroyEntities) {
entities.push_back(em->create());
}
- boost::timer::auto_cpu_timer t;
+ AutoTimer t;
cout << "destroying " << count << " entities" << endl;
for (auto e : entities) {
@@ -54,7 +64,7 @@ TEST_F(BenchmarksTest, TestCreateEntitiesWithListener) {
uint64_t count = 10000000L;
- boost::timer::auto_cpu_timer t;
+ AutoTimer t;
cout << "creating " << count << " entities while notifying a single EntityCreatedEvent listener" << endl;
vector<Entity> entities;
@@ -73,7 +83,7 @@ TEST_F(BenchmarksTest, TestDestroyEntitiesWithListener) {
entities.push_back(em->create());
}
- boost::timer::auto_cpu_timer t;
+ AutoTimer t;
cout << "destroying " << count << " entities" << endl;
for (auto &e : entities) {
@@ -93,7 +103,7 @@ TEST_F(BenchmarksTest, TestEntityIteration) {
entities.push_back(e);
}
- boost::timer::auto_cpu_timer t;
+ AutoTimer t;
cout << "iterating over " << count << " entities with a component 10 times" << endl;
for (int i = 0; i < 10; ++i) {
diff --git a/entityx/help/NonCopyable.h b/entityx/help/NonCopyable.h
index 5f193ee..19c0ed1 100644
--- a/entityx/help/NonCopyable.h
+++ b/entityx/help/NonCopyable.h
@@ -5,19 +5,16 @@
namespace entityx {
namespace help {
-class NonCopyable
-{
- protected:
-
+class NonCopyable {
+protected:
NonCopyable() = default;
~NonCopyable() = default;
- NonCopyable( const NonCopyable& ) = delete;
- NonCopyable& operator=( const NonCopyable& ) = delete;
-
+ NonCopyable(const NonCopyable&) = delete;
+ NonCopyable& operator = (const NonCopyable &) = delete;
};
-} // namespace help
-} // namespace entityx \ No newline at end of file
+} // namespace help
+} // namespace entityx
diff --git a/entityx/help/Timer.cc b/entityx/help/Timer.cc
index 0b18c84..5f70ee0 100644
--- a/entityx/help/Timer.cc
+++ b/entityx/help/Timer.cc
@@ -13,25 +13,21 @@
namespace entityx {
namespace help {
-Timer::Timer()
-{
-
+Timer::Timer() {
+ _start = std::chrono::system_clock::now();
}
-Timer::~Timer()
-{
-
+Timer::~Timer() {
}
-void Timer::restart()
-{
- _start = std::chrono::system_clock::now();
+void Timer::restart() {
+ _start = std::chrono::system_clock::now();
}
-double Timer::elapsed()
-{
- return std::chrono::duration<double>(std::chrono::system_clock::now() - _start).count();
+double Timer::elapsed() {
+ auto duration = std::chrono::system_clock::now() - _start;
+ return static_cast<double>(std::chrono::duration_cast<std::chrono::milliseconds>(duration).count()) / 1000.0;
}
-} // namespace help
-} // namespace entityx \ No newline at end of file
+} // namespace help
+} // namespace entityx
diff --git a/entityx/help/Timer.h b/entityx/help/Timer.h
index 87a0626..4d22b08 100644
--- a/entityx/help/Timer.h
+++ b/entityx/help/Timer.h
@@ -9,22 +9,21 @@
*/
#pragma once
- #include <chrono>
+#include <chrono>
namespace entityx {
namespace help {
-class Timer
-{
+class Timer {
public:
- Timer();
- ~Timer();
+ Timer();
+ ~Timer();
- void restart();
- double elapsed();
+ void restart();
+ double elapsed();
private:
- std::chrono::time_point<std::chrono::system_clock> _start;
+ std::chrono::time_point<std::chrono::system_clock> _start;
};
-} // namespace help
-} // namespace entityx \ No newline at end of file
+} // namespace help
+} // namespace entityx