#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)) {}
TEST_F(BenchmarksTest, TestCreateEntities) {
- boost::timer::auto_cpu_timer t;
+ AutoTimer t;
uint64_t count = 10000000L;
cout << "creating " << count << " entities" << endl;
entities.push_back(em->create());
}
- boost::timer::auto_cpu_timer t;
+ AutoTimer t;
cout << "destroying " << count << " entities" << endl;
for (auto e : entities) {
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;
entities.push_back(em->create());
}
- boost::timer::auto_cpu_timer t;
+ AutoTimer t;
cout << "destroying " << count << " entities" << endl;
for (auto &e : entities) {
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) {
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
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