From 1a6a12a8b3310400a103e0048b7ed747fc479398 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 13 May 2015 20:59:09 +0300 Subject: Add initial support for custom stack class. In some tests it 3 times faster in push than std::stack. --- src/test/testlauncher.cpp | 89 +++++++++++++++++++++++++++++++++++++++++++++++ src/test/testlauncher.h | 2 ++ 2 files changed, 91 insertions(+) (limited to 'src/test') diff --git a/src/test/testlauncher.cpp b/src/test/testlauncher.cpp index 244f8b8fd..ffe16e8e7 100644 --- a/src/test/testlauncher.cpp +++ b/src/test/testlauncher.cpp @@ -30,6 +30,8 @@ #include "gui/skin.h" #include "gui/theme.h" +#include "gui/cliprect.h" + #include "gui/fonts/font.h" #include "utils/physfscheckutils.h" @@ -39,6 +41,7 @@ #include "resources/dyepalette.h" #include "resources/image.h" #include "resources/imagewriter.h" +#include "resources/mstack.h" #include "resources/openglimagehelper.h" #include "resources/surfaceimagehelper.h" #include "resources/wallpaper.h" @@ -97,6 +100,8 @@ int TestLauncher::exec() return testFps3(); else if (mTest == "105") return testDyeSpeed(); + else if (mTest == "106") + return testStackSpeed(); return -1; } @@ -486,6 +491,90 @@ int TestLauncher::testDyeSpeed() return 0; } +int TestLauncher::testStackSpeed() +{ + const int sz = 100000; + const int k = 100; + const int sz2 = sz * k; + + std::stack stack1; + MStack stack2(sz2); + timespec time1; + timespec time2; + +#if defined __linux__ || defined __linux + + for (int d = 0; d < 100; d ++) + { + for (int f = 0; f < sz; f ++) + { + ClipRect rect; + rect.xOffset = f; + rect.yOffset = f; + stack1.push(rect); + } + } + while (!stack1.empty()) + stack1.pop(); + + clock_gettime(CLOCK_MONOTONIC, &time1); + + for (int d = 0; d < 100; d ++) + { + for (int f = 0; f < sz; f ++) + { + ClipRect rect; + rect.xOffset = f; + rect.yOffset = f; + stack1.push(rect); + } + } + + clock_gettime(CLOCK_MONOTONIC, &time2); + long diff = ((static_cast(time2.tv_sec) * 1000000000L + + static_cast(time2.tv_nsec)) / 1) - + ((static_cast(time1.tv_sec) * 1000000000L + + static_cast(time1.tv_nsec)) / 1); + printf("debug: %d\n", stack1.top().xOffset); + printf("stl time: %ld\n", diff); + + + + for (int d = 0; d < 100; d ++) + { + for (int f = 0; f < sz; f ++) + { + ClipRect &rect = stack2.push(); + rect.xOffset = f; + rect.yOffset = f; + } + } + stack2.clear(); + + clock_gettime(CLOCK_MONOTONIC, &time1); + + for (int d = 0; d < 100; d ++) + { + for (int f = 0; f < sz; f ++) + { + ClipRect &rect = stack2.push(); + rect.xOffset = f; + rect.yOffset = f; + } + } + + clock_gettime(CLOCK_MONOTONIC, &time2); + diff = ((static_cast(time2.tv_sec) * 1000000000L + + static_cast(time2.tv_nsec)) / 1) - + ((static_cast(time1.tv_sec) * 1000000000L + + static_cast(time1.tv_nsec)) / 1); + printf("debug: %d\n", stack2.top().xOffset); + printf("my time: %ld\n", diff); + +#endif + return 0; +} + int TestLauncher::testDraw() { Image *img[3]; diff --git a/src/test/testlauncher.h b/src/test/testlauncher.h index abb84483b..d82e48f3f 100644 --- a/src/test/testlauncher.h +++ b/src/test/testlauncher.h @@ -72,6 +72,8 @@ class TestLauncher final int testDyeSpeed(); + int testStackSpeed(); + private: std::string mTest; -- cgit v1.2.3-70-g09d2