diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2017-02-26 18:58:25 -0500 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2017-02-26 18:58:25 -0500 |
commit | f4c47aa1845e996dea89ed17c2d71752df50ed50 (patch) | |
tree | 735b09c57119f58641243a212833c244324fd9c6 | |
parent | 7be6cc9a3ec6aaf818a24ad97201a4d1e67e6586 (diff) |
reorginization
-rw-r--r-- | Makefile | 7 | ||||
-rw-r--r-- | README.md | 68 | ||||
-rw-r--r-- | main.cpp | 207 | ||||
-rw-r--r-- | tests/EntityXBenchmark.h (renamed from EntityXBenchmark.h) | 0 | ||||
-rw-r--r-- | tests/Makefile | 4 | ||||
-rw-r--r-- | tests/benchpress.hpp (renamed from benchpress.hpp) | 0 | ||||
-rw-r--r-- | tests/cxxopts.hpp (renamed from cxxopts.hpp) | 0 | ||||
-rw-r--r-- | tests/entitiesBenchmark.h (renamed from entitiesBenchmark.h) | 2 | ||||
-rwxr-xr-x | tests/entitiesTests | bin | 0 -> 265704 bytes | |||
-rw-r--r-- | tests/entitiesTests.cpp (renamed from bench.cpp) | 16 | ||||
-rwxr-xr-x | tests/entityXTests | bin | 0 -> 787720 bytes | |||
-rw-r--r-- | tests/entityXTests.cpp (renamed from xtest.cpp) | 0 |
12 files changed, 47 insertions, 257 deletions
diff --git a/Makefile b/Makefile deleted file mode 100644 index b1a2703..0000000 --- a/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -all: - g++ -std=c++17 -ggdb -pedantic -Wall -Wextra main.cpp -o main -lentityx - -test: - g++ -std=c++17 -Wall -Wextra bench.cpp -o test -O1 - g++ -std=c++17 -Wall -Wextra xtest.cpp -o xtest -O1 -lentityx - @@ -7,43 +7,43 @@ The file that actually contains the library is entities.hpp. ## compared to EntityX entities: ``` -entityx create destroy entity with components 5000000 254 ns/op - [25] entityx 25 entities component systems update 1000000 1572 ns/op - [50] entityx 50 entities component systems update 500000 3009 ns/op - [100] entityx 100 entities component systems update 200000 5995 ns/op - [200] entityx 200 entities component systems update 100000 11848 ns/op - [400] entityx 400 entities component systems update 50000 23631 ns/op - [800] entityx 800 entities component systems update 20000 51669 ns/op - [1600] entityx 1600 entities component systems update 10000 112446 ns/op - [3200] entityx 3200 entities component systems update 5000 225504 ns/op - [5000] entityx 5000 entities component systems update 5000 368282 ns/op - [10000] entityx 10000 entities component systems update 1000 1240502 ns/op - [30000] entityx 30000 entities component systems update 200 5196731 ns/op - [100000] entityx 100000 entities component systems update 100 18331731 ns/op - [500000] entityx 500000 entities component systems update 20 93182044 ns/op - [1000000] entityx 1000000 entities component systems update 10 191315282 ns/op - [2000000] entityx 2000000 entities component systems update 5 299790721 ns/op -./test 43.175s +entities create destroy entity with components 5000000 279 ns/op + [25] entities 25 entities component systems update 1000000 1610 ns/op + [50] entities 50 entities component systems update 500000 3098 ns/op + [100] entities 100 entities component systems update 200000 6247 ns/op + [200] entities 200 entities component systems update 100000 12274 ns/op + [400] entities 400 entities component systems update 50000 25029 ns/op + [800] entities 800 entities component systems update 20000 55717 ns/op + [1600] entities 1600 entities component systems update 10000 116305 ns/op + [3200] entities 3200 entities component systems update 5000 244461 ns/op + [5000] entities 5000 entities component systems update 5000 463835 ns/op + [10000] entities 10000 entities component systems update 1000 1647042 ns/op + [30000] entities 30000 entities component systems update 200 5784773 ns/op + [100000] entities 100000 entities component systems update 50 20711117 ns/op + [500000] entities 500000 entities component systems update 20 103582654 ns/op + [1000000] entities 1000000 entities component systems update 10 208073004 ns/op + [2000000] entities 2000000 entities component systems update 5 341977621 ns/op +./entitiesTests 45.328s ``` EntityX: ``` -entityx create destroy entity with components 5000000 200 ns/op - [25] entityx 25 entities component systems update 500000 2903 ns/op - [50] entityx 50 entities component systems update 200000 5721 ns/op - [100] entityx 100 entities component systems update 100000 11338 ns/op - [200] entityx 200 entities component systems update 50000 22622 ns/op - [400] entityx 400 entities component systems update 50000 45560 ns/op - [800] entityx 800 entities component systems update 20000 92718 ns/op - [1600] entityx 1600 entities component systems update 10000 180159 ns/op - [3200] entityx 3200 entities component systems update 5000 360127 ns/op - [5000] entityx 5000 entities component systems update 2000 563316 ns/op - [10000] entityx 10000 entities component systems update 1000 1130659 ns/op - [30000] entityx 30000 entities component systems update 500 3431964 ns/op - [100000] entityx 100000 entities component systems update 100 11680312 ns/op - [500000] entityx 500000 entities component systems update 20 59996331 ns/op - [1000000] entityx 1000000 entities component systems update 10 128663563 ns/op - [2000000] entityx 2000000 entities component systems update 5 271582063 ns/op -./xtest 41.912s +entityx create destroy entity with components 5000000 212 ns/op + [25] entityx 25 entities component systems update 500000 3025 ns/op + [50] entityx 50 entities component systems update 200000 6274 ns/op + [100] entityx 100 entities component systems update 100000 12101 ns/op + [200] entityx 200 entities component systems update 50000 24227 ns/op + [400] entityx 400 entities component systems update 50000 48100 ns/op + [800] entityx 800 entities component systems update 20000 95872 ns/op + [1600] entityx 1600 entities component systems update 10000 196251 ns/op + [3200] entityx 3200 entities component systems update 5000 397806 ns/op + [5000] entityx 5000 entities component systems update 2000 623035 ns/op + [10000] entityx 10000 entities component systems update 1000 1279807 ns/op + [30000] entityx 30000 entities component systems update 500 3791401 ns/op + [100000] entityx 100000 entities component systems update 100 13074271 ns/op + [500000] entityx 500000 entities component systems update 20 65787539 ns/op + [1000000] entityx 1000000 entities component systems update 10 137753731 ns/op + [2000000] entityx 2000000 entities component systems update 5 290476228 ns/op +./entityXTests 45.232s ``` You can find EntityX [here](https://github.com/alecthomas/entityx). diff --git a/main.cpp b/main.cpp deleted file mode 100644 index 0d77c8d..0000000 --- a/main.cpp +++ /dev/null @@ -1,207 +0,0 @@ -#include <iostream> -#include <string> -#include <ctime> -#include <functional> -#include <iomanip> - -#include "entities.hpp" - -#include <entityx/entityx.h> -#include <entityx/deps/Dependencies.h> - -using TestFunc = std::function<void(void)>; -constexpr unsigned int testCount = 100; - -void test(const std::string& t, TestFunc ours, TestFunc theirs) -{ - auto run = [](auto f) { - clock_t avg = 0; - for (unsigned int i = 0; i < testCount; i++) { - auto start = clock(); - f(); - auto diff = clock() - start; - avg += diff; - } - auto diff = avg / testCount; - std::cout << "Test took " << - diff << " ticks (" << diff / static_cast<double>(CLOCKS_PER_SEC) << - "ms).\n"; - return diff; - }; - - std::cout << std::fixed << std::setprecision(6); - std::cout << "==============================================\n"; - std::cout << "Running test: " << t << "\n"; - - std::cout << "Ours:\n"; - auto o = run(ours); - - std::cout << "Theirs:\n"; - auto p = run(theirs); - - auto percent = (o - p) / static_cast<float>(p); - std::cout << "\nDIFFERENCE: " << o - p << " ticks (" << - std::setprecision(2) << percent << "%).\n\n"; -} - -struct Position : public Component { - float x, y; - - Position(float _x = 0, float _y = 0) - : x(_x), y(_y) {} -}; - -struct Velocity : public Component { - float x, y; - Velocity(float _x = 0, float _y = 0) - : x(_x), y(_y) {} -}; - -int main(void) -{ - EntityManager em; - - entityx::EventManager ev; - entityx::EntityManager xm (ev); - entityx::SystemManager xsm (xm, ev); - - test("Creation500", - [&em](){ - for (int i = 0; i < 500; i++) - em.create(); - }, - [&xm](){ - for (int i = 0; i < 500; i++) - xm.create(); - }); - - test("Reset", - [&em](){ - em.reset(); - }, - [&xm](){ - xm.reset(); - }); - - test("Assign", - [&em](){ - auto e = em.create(); - auto& pos = *e.assign<Position>(12, 34); - - //std::cout << pos.x << ' ' << pos.y << '\n'; - pos.x = 56, pos.y = 16; - //std::cout << pos.x << ' ' << pos.y << '\n'; - }, - [&xm](){ - auto e = xm.create(); - auto pos = e.assign<Position>(12, 34); - - //std::cout << pos->x << ' ' << pos->y << '\n'; - pos->x = 56, pos->y = 16; - //std::cout << pos->x << ' ' << pos->y << '\n'; - - }); - - test("HasComponent", - [&em](){ - auto e = em.create(); - //std::cout << e.hasComponent<Position>() << '\n'; - e.assign<Position>(); - //std::cout << e.hasComponent<Position>() << '\n'; - }, - [&xm](){ - auto e = xm.create(); - //std::cout << e.has_component<Position>() << '\n'; - e.assign<Position>(); - //std::cout << e.has_component<Position>() << '\n'; - }); - - test("Remove", - [&em](){ - auto e = em.create(); - //std::cout << e.hasComponent<Position>() << '\n'; - e.assign<Position>(); - //std::cout << e.hasComponent<Position>() << '\n'; - e.remove<Position>(); - //std::cout << e.hasComponent<Position>() << '\n'; - }, - [&xm](){ - auto e = xm.create(); - //std::cout << e.has_component<Position>() << '\n'; - e.assign<Position>(); - //std::cout << e.has_component<Position>() << '\n'; - e.remove<Position>(); - //std::cout << e.has_component<Position>() << '\n'; - }); - - /*test("EachAll", [&em](){ - em.reset(); - em.create(), em.create(), em.create(); - int i = 0; - em.each([&i](Entity e) { - std::cout << ++i << '\n'; - }); - });*/ - - test("EachSpec", - [&em](){ - em.reset(); - em.create(), em.create(); - auto e1 = em.create(); e1.assign<Position>(1, 3); - em.create(); - auto e2 = em.create(); e2.assign<Position>(99); - - em.each<Position>([](Entity e) { - auto& pos = *e.component<Position>(); - //std::cout << pos.x << ' ' << pos.y << '\n'; - }); - }, - [&xm](){ - xm.reset(); - xm.create(), xm.create(); - auto e1 = xm.create(); e1.assign<Position>(1, 3); - xm.create(); - auto e2 = xm.create(); e2.assign<Position>(99); - - xm.each<Position>([](entityx::Entity e, Position& pos) { - //std::cout << pos.x << ' ' << pos.y << '\n'; - }); - }); - - test("Loop100", - [&em](){ - for (int i = 100; i--;) { - auto e = em.create(); - e.assign<Position>(i, i); - } - em.each<Position>([](Entity e) { - auto& pos = * e.component<Position>(); - pos.x += 5, pos.y -= 5; - }); - }, - [&xm](){ - for (int i = 100; i--;) { - auto e = xm.create(); - e.assign<Position>(i, i); - } - xm.each<Position>([](entityx::Entity e, Position pos) { - pos.x += 5, pos.y -= 5; - }); - }); - - /*test("Dependency", - [&em](){ - em.addDependency<Velocity, Position>(); - auto e = em.create(); - e.assign<Velocity>(); - std::cout << e.hasComponent<Position>() << e.hasComponent<Velocity>() << '\n'; - }, - [&xm, &xsm](){ - xsm.add<entityx::deps::Dependency<Velocity, Position>>(); - auto e = xm.create(); - e.assign<Velocity>(); - std::cout << e.has_component<Position>() << e.has_component<Velocity>() << '\n'; - });*/ - - return 0; -} diff --git a/EntityXBenchmark.h b/tests/EntityXBenchmark.h index defa37c..defa37c 100644 --- a/EntityXBenchmark.h +++ b/tests/EntityXBenchmark.h diff --git a/tests/Makefile b/tests/Makefile new file mode 100644 index 0000000..bf69813 --- /dev/null +++ b/tests/Makefile @@ -0,0 +1,4 @@ +all: + g++ -std=c++17 -Wall -Wextra entitiesTests.cpp -o entitiesTests -O1 + g++ -std=c++17 -Wall -Wextra entityXTests.cpp -o entityXTests -O1 -lentityx + diff --git a/benchpress.hpp b/tests/benchpress.hpp index cb1bff4..cb1bff4 100644 --- a/benchpress.hpp +++ b/tests/benchpress.hpp diff --git a/cxxopts.hpp b/tests/cxxopts.hpp index 047190e..047190e 100644 --- a/cxxopts.hpp +++ b/tests/cxxopts.hpp diff --git a/entitiesBenchmark.h b/tests/entitiesBenchmark.h index dcf22f1..e046fe3 100644 --- a/entitiesBenchmark.h +++ b/tests/entitiesBenchmark.h @@ -8,7 +8,7 @@ #include <numeric> #include <functional> -#include "entities.hpp" +#include "../entities.hpp" class EntitiesBenchmark { public: diff --git a/tests/entitiesTests b/tests/entitiesTests Binary files differnew file mode 100755 index 0000000..719c8e1 --- /dev/null +++ b/tests/entitiesTests diff --git a/bench.cpp b/tests/entitiesTests.cpp index 99824ac..8ea2b92 100644 --- a/bench.cpp +++ b/tests/entitiesTests.cpp @@ -6,7 +6,7 @@ #define BENCHPRESS_CONFIG_MAIN #include "benchpress.hpp" -#include "entities.hpp" +#include "../entities.hpp" #include "entitiesBenchmark.h" @@ -23,7 +23,7 @@ inline void init_entities(EntityManager& entities, size_t nentities){ } } -inline void runEntitiesSystemsEntityXBenchmark(benchpress::context* ctx, size_t nentities) { +inline void runEntitiesSystemsEntitiesBenchmark(benchpress::context* ctx, size_t nentities) { EntitiesBenchmark::Application app; auto& entities = app.em; @@ -38,7 +38,7 @@ inline void runEntitiesSystemsEntityXBenchmark(benchpress::context* ctx, size_t -BENCHMARK("entityx create destroy entity with components", [](benchpress::context* ctx) { +BENCHMARK("entities create destroy entity with components", [](benchpress::context* ctx) { EntityManager entities; ctx->reset_timer(); @@ -57,7 +57,7 @@ BENCHMARK("entityx create destroy entity with components", [](benchpress::contex -class BenchmarksEntityX { +class BenchmarksEntities { public: static const std::vector<int> ENTITIES; @@ -77,16 +77,16 @@ class BenchmarksEntityX { std::string benchmark_name = ss.str(); BENCHMARK(benchmark_name, [nentities](benchpress::context* ctx) { - runEntitiesSystemsEntityXBenchmark(ctx, nentities); + runEntitiesSystemsEntitiesBenchmark(ctx, nentities); }) } } - BenchmarksEntityX(std::string name){ + BenchmarksEntities(std::string name){ makeBenchmarks(name); } }; -const std::vector<int> BenchmarksEntityX::ENTITIES = { +const std::vector<int> BenchmarksEntities::ENTITIES = { 25, 50, 100, 200, 400, 800, 1600, 3200, 5000, @@ -95,7 +95,7 @@ const std::vector<int> BenchmarksEntityX::ENTITIES = { 1'000'000, 2'000'000 }; -BenchmarksEntityX entityxbenchmarks ("entityx"); +BenchmarksEntities entitiesBenchmarks ("entities"); diff --git a/tests/entityXTests b/tests/entityXTests Binary files differnew file mode 100755 index 0000000..514d5f4 --- /dev/null +++ b/tests/entityXTests diff --git a/xtest.cpp b/tests/entityXTests.cpp index 2f814c5..2f814c5 100644 --- a/xtest.cpp +++ b/tests/entityXTests.cpp |