Skip to content

Commit

Permalink
add test performance
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubpa committed Jul 29, 2020
1 parent 7e1d1bb commit 0749089
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/test/13_performance/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Ubpa_GetTargetName(core "${PROJECT_SOURCE_DIR}/src/core")
Ubpa_AddTarget(
TEST
MODE EXE
LIB ${core}
)
42 changes: 42 additions & 0 deletions src/test/13_performance/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <UECS/World.h>

#include <chrono>
#include <iostream>

struct A { float val; };
struct B { float val; };

struct TestSystem {
static void OnUpdate(Ubpa::Schedule& schedule) {
schedule.Register(
[](const A* a, B* b) {
// 256 floating-point operations
for (size_t i = 0; i < 256; i++)
b->val *= a->val;
}, "TestSystem");
}
};

int main() {
size_t numEntities = 65536;
size_t numUpdate = 144 * 10;
Ubpa::World w;
w.systemMngr.Register<TestSystem>();

auto t0 = std::chrono::steady_clock::now();
for (size_t i = 0; i < numEntities; i++)
w.entityMngr.Create<A, B>();
auto t1 = std::chrono::steady_clock::now();
for (size_t i = 0; i < numUpdate; i++)
w.Update();
auto t2 = std::chrono::steady_clock::now();

// about 10s
// G5400 : 4 core
auto d0 = t1 - t0;
auto d1 = t2 - t1;
std::cout << "create: " << d0.count() / 1000000000.0 << "s" << std::endl;
std::cout << "update: " << d1.count() / 1000000000.0 << "s" << std::endl;

return 0;
}

0 comments on commit 0749089

Please sign in to comment.