From 0749089d9295ae7519e842d48229c94298c900ad Mon Sep 17 00:00:00 2001 From: Ubpa <641614112@qq.com> Date: Wed, 29 Jul 2020 21:31:50 +0800 Subject: [PATCH] add test performance --- src/test/13_performance/CMakeLists.txt | 6 ++++ src/test/13_performance/main.cpp | 42 ++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 src/test/13_performance/CMakeLists.txt create mode 100644 src/test/13_performance/main.cpp diff --git a/src/test/13_performance/CMakeLists.txt b/src/test/13_performance/CMakeLists.txt new file mode 100644 index 0000000..ec4a795 --- /dev/null +++ b/src/test/13_performance/CMakeLists.txt @@ -0,0 +1,6 @@ +Ubpa_GetTargetName(core "${PROJECT_SOURCE_DIR}/src/core") +Ubpa_AddTarget( + TEST + MODE EXE + LIB ${core} +) diff --git a/src/test/13_performance/main.cpp b/src/test/13_performance/main.cpp new file mode 100644 index 0000000..2aa8107 --- /dev/null +++ b/src/test/13_performance/main.cpp @@ -0,0 +1,42 @@ +#include + +#include +#include + +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(); + + auto t0 = std::chrono::steady_clock::now(); + for (size_t i = 0; i < numEntities; i++) + w.entityMngr.Create(); + 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; +}