Merge pull request #6291 from dumganhar/perf-callback

Adds performance test for callbacks: 1) std::function,2) (target->*selector)(), 3) simulate new api of Scheduler
This commit is contained in:
James Chen 2014-04-25 12:42:16 +08:00
commit d885882ef5
13 changed files with 349 additions and 3 deletions

View File

@ -1 +1 @@
e569f7828939a72dd90b17fea3e60f6b9fe3da16
2dcda958098d34a161aadd25d3afdab6b5a936e4

View File

@ -152,6 +152,7 @@ Classes/PerformanceTest/PerformanceRendererTest.cpp \
Classes/PerformanceTest/PerformanceContainerTest.cpp \
Classes/PerformanceTest/PerformanceEventDispatcherTest.cpp \
Classes/PerformanceTest/PerformanceScenarioTest.cpp \
Classes/PerformanceTest/PerformanceCallbackTest.cpp \
Classes/PhysicsTest/PhysicsTest.cpp \
Classes/ReleasePoolTest/ReleasePoolTest.cpp \
Classes/RenderTextureTest/RenderTextureTest.cpp \

View File

@ -147,6 +147,7 @@ set(SAMPLE_SRC
Classes/PerformanceTest/PerformanceContainerTest.cpp
Classes/PerformanceTest/PerformanceEventDispatcherTest.cpp
Classes/PerformanceTest/PerformanceScenarioTest.cpp
Classes/PerformanceTest/PerformanceCallbackTest.cpp
Classes/PhysicsTest/PhysicsTest.cpp
Classes/ReleasePoolTest/ReleasePoolTest.cpp
Classes/RenderTextureTest/RenderTextureTest.cpp

View File

@ -0,0 +1,218 @@
//
// PerformanceCallbackTest.cpp
//
#include "PerformanceCallbackTest.h"
#include <algorithm>
// Enable profiles for this file
#undef CC_PROFILER_DISPLAY_TIMERS
#define CC_PROFILER_DISPLAY_TIMERS() Profiler::getInstance()->displayTimers()
#undef CC_PROFILER_PURGE_ALL
#define CC_PROFILER_PURGE_ALL() Profiler::getInstance()->releaseAllTimers()
#undef CC_PROFILER_START
#define CC_PROFILER_START(__name__) ProfilingBeginTimingBlock(__name__)
#undef CC_PROFILER_STOP
#define CC_PROFILER_STOP(__name__) ProfilingEndTimingBlock(__name__)
#undef CC_PROFILER_RESET
#define CC_PROFILER_RESET(__name__) ProfilingResetTimingBlock(__name__)
#undef CC_PROFILER_START_CATEGORY
#define CC_PROFILER_START_CATEGORY(__cat__, __name__) do{ if(__cat__) ProfilingBeginTimingBlock(__name__); } while(0)
#undef CC_PROFILER_STOP_CATEGORY
#define CC_PROFILER_STOP_CATEGORY(__cat__, __name__) do{ if(__cat__) ProfilingEndTimingBlock(__name__); } while(0)
#undef CC_PROFILER_RESET_CATEGORY
#define CC_PROFILER_RESET_CATEGORY(__cat__, __name__) do{ if(__cat__) ProfilingResetTimingBlock(__name__); } while(0)
#undef CC_PROFILER_START_INSTANCE
#define CC_PROFILER_START_INSTANCE(__id__, __name__) do{ ProfilingBeginTimingBlock( String::createWithFormat("%08X - %s", __id__, __name__)->getCString() ); } while(0)
#undef CC_PROFILER_STOP_INSTANCE
#define CC_PROFILER_STOP_INSTANCE(__id__, __name__) do{ ProfilingEndTimingBlock( String::createWithFormat("%08X - %s", __id__, __name__)->getCString() ); } while(0)
#undef CC_PROFILER_RESET_INSTANCE
#define CC_PROFILER_RESET_INSTANCE(__id__, __name__) do{ ProfilingResetTimingBlock( String::createWithFormat("%08X - %s", __id__, __name__)->getCString() ); } while(0)
static std::function<PerformanceCallbackScene*()> createFunctions[] =
{
CL(SimulateNewSchedulerCallbackPerfTest),
CL(InvokeMemberFunctionPerfTest),
CL(InvokeStdFunctionPerfTest),
};
#define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0]))
static int g_curCase = 0;
////////////////////////////////////////////////////////
//
// CallbackBasicLayer
//
////////////////////////////////////////////////////////
CallbackBasicLayer::CallbackBasicLayer(bool bControlMenuVisible, int nMaxCases, int nCurCase)
: PerformBasicLayer(bControlMenuVisible, nMaxCases, nCurCase)
{
}
void CallbackBasicLayer::showCurrentTest()
{
auto scene = createFunctions[_curCase]();
g_curCase = _curCase;
if (scene)
{
Director::getInstance()->replaceScene(scene);
}
}
////////////////////////////////////////////////////////
//
// PerformanceCallbackScene
//
////////////////////////////////////////////////////////
void PerformanceCallbackScene::onEnter()
{
Scene::onEnter();
CC_PROFILER_PURGE_ALL();
auto s = Director::getInstance()->getWinSize();
auto menuLayer = new CallbackBasicLayer(true, MAX_LAYER, g_curCase);
addChild(menuLayer);
menuLayer->release();
// Title
auto label = Label::createWithTTF(title().c_str(), "fonts/arial.ttf", 32);
addChild(label, 1);
label->setPosition(Point(s.width/2, s.height-50));
// Subtitle
std::string strSubTitle = subtitle();
if(strSubTitle.length())
{
auto l = Label::createWithTTF(strSubTitle.c_str(), "fonts/Thonburi.ttf", 16);
addChild(l, 1);
l->setPosition(Point(s.width/2, s.height-80));
}
getScheduler()->schedule(schedule_selector(PerformanceCallbackScene::onUpdate), this, 0.0f, false);
getScheduler()->schedule(schedule_selector(PerformanceCallbackScene::dumpProfilerInfo), this, 2, false);
}
std::string PerformanceCallbackScene::title() const
{
return "No title";
}
std::string PerformanceCallbackScene::subtitle() const
{
return "";
}
void PerformanceCallbackScene::dumpProfilerInfo(float dt)
{
CC_PROFILER_DISPLAY_TIMERS();
}
////////////////////////////////////////////////////////
//
// SimulateNewSchedulerCallbackPerfTest
//
////////////////////////////////////////////////////////
void SimulateNewSchedulerCallbackPerfTest::onEnter()
{
PerformanceCallbackScene::onEnter();
_profileName = "SimulateNewScheduler";
this->simulateScheduleUpdate(this);
}
void SimulateNewSchedulerCallbackPerfTest::onUpdate(float dt)
{
CC_PROFILER_START(_profileName.c_str());
for (int i = 0; i < LOOP_COUNT; ++i)
{
_callback(dt);
}
CC_PROFILER_STOP(_profileName.c_str());
}
std::string SimulateNewSchedulerCallbackPerfTest::title() const
{
return "Simulate scheduler in 3.0 Perf test";
}
std::string SimulateNewSchedulerCallbackPerfTest::subtitle() const
{
return "See console";
}
// InvokeMemberFunctionPerfTest
void InvokeMemberFunctionPerfTest::onEnter()
{
PerformanceCallbackScene::onEnter();
_profileName = "InvokeMemberFunction";
_target = this;
_selector = schedule_selector(InvokeMemberFunctionPerfTest::update);
}
std::string InvokeMemberFunctionPerfTest::title() const
{
return "Invoke Member function pert test";
}
std::string InvokeMemberFunctionPerfTest::subtitle() const
{
return "See console";
}
void InvokeMemberFunctionPerfTest::onUpdate(float dt)
{
CC_PROFILER_START(_profileName.c_str());
for (int i = 0; i < LOOP_COUNT; ++i)
{
(_target->*_selector)(dt);
}
CC_PROFILER_STOP(_profileName.c_str());
}
void InvokeStdFunctionPerfTest::onEnter()
{
PerformanceCallbackScene::onEnter();
_profileName = "InvokeStdFunction";
_callback = CC_CALLBACK_1(InvokeStdFunctionPerfTest::update, this);
}
std::string InvokeStdFunctionPerfTest::title() const
{
return "Invoke std function pert test";
}
std::string InvokeStdFunctionPerfTest::subtitle() const
{
return "See console";
}
void InvokeStdFunctionPerfTest::onUpdate(float dt)
{
CC_PROFILER_START(_profileName.c_str());
for (int i = 0; i < LOOP_COUNT; ++i)
{
_callback(dt);
}
CC_PROFILER_STOP(_profileName.c_str());
}
void runCallbackPerformanceTest()
{
auto scene = createFunctions[g_curCase]();
Director::getInstance()->replaceScene(scene);
}

View File

@ -0,0 +1,102 @@
//
// PerformanceCallbackTest.h
#ifndef __PERFORMANCE_CALLBACK_TEST_H__
#define __PERFORMANCE_CALLBACK_TEST_H__
#include "PerformanceTest.h"
#include "CCProfiling.h"
class CallbackBasicLayer : public PerformBasicLayer
{
public:
CallbackBasicLayer(bool bControlMenuVisible, int nMaxCases = 0, int nCurCase = 0);
virtual void showCurrentTest();
};
class PerformanceCallbackScene : public Scene
{
public:
virtual void onEnter() override;
virtual std::string title() const;
virtual std::string subtitle() const;
virtual void onUpdate(float dt) {};
void dumpProfilerInfo(float dt);
protected:
std::string _profileName;
int _placeHolder; // To avoid compiler optimization
static const int LOOP_COUNT = 10000;
};
class SimulateNewSchedulerCallbackPerfTest : public PerformanceCallbackScene
{
public:
CREATE_FUNC(SimulateNewSchedulerCallbackPerfTest);
// overrides
virtual void onEnter() override;
virtual std::string title() const override;
virtual std::string subtitle() const override;
virtual void onUpdate(float dt) override;
virtual void update(float dt) override { _placeHolder = 100; };
void simulateSchedulePerFrame(const std::function<void(float)>& callback)
{
_callback = callback;
}
template <class T>
void simulateScheduleUpdate(T* target)
{
target->simulateSchedulePerFrame([target](float dt){
target->update(dt);
});
}
private:
std::function<void(float)> _callback;
};
// InvokeMemberFunctionPerfTest
class InvokeMemberFunctionPerfTest : public PerformanceCallbackScene
{
public:
CREATE_FUNC(InvokeMemberFunctionPerfTest);
virtual void onEnter() override;
virtual std::string title() const override;
virtual std::string subtitle() const override;
virtual void onUpdate(float dt) override;
virtual void update(float dt) override { _placeHolder = 200; };
private:
Node* _target;
SEL_SCHEDULE _selector;
};
// InvokeStdFunctionPerfTest
class InvokeStdFunctionPerfTest : public PerformanceCallbackScene
{
public:
CREATE_FUNC(InvokeStdFunctionPerfTest);
// overrides
virtual void onEnter() override;
virtual std::string title() const override;
virtual std::string subtitle() const override;
virtual void onUpdate(float dt) override;
virtual void update(float dt) override { _placeHolder = 100; };
private:
std::function<void(float)> _callback;
};
void runCallbackPerformanceTest();
#endif /* __PERFORMANCE_CALLBACK_TEST_H__ */

View File

@ -154,8 +154,6 @@ void PerformanceEventDispatcherScene::initWithQuantityOfNodes(unsigned int nNode
addChild(menuLayer);
menuLayer->release();
printf("Size of Node: %lu\n", sizeof(Node));
int oldFontSize = MenuItemFont::getFontSize();
MenuItemFont::setFontSize(24);

View File

@ -11,6 +11,7 @@
#include "PerformanceContainerTest.h"
#include "PerformanceEventDispatcherTest.h"
#include "PerformanceScenarioTest.h"
#include "PerformanceCallbackTest.h"
enum
{
@ -34,6 +35,7 @@ struct {
{ "Container Perf Test", [](Ref* sender ) { runContainerPerformanceTest(); } },
{ "EventDispatcher Perf Test", [](Ref* sender ) { runEventDispatcherPerformanceTest(); } },
{ "Scenario Perf Test", [](Ref* sender ) { runScenarioTest(); } },
{ "Callback Perf Test", [](Ref* sender ) { runCallbackPerformanceTest(); } },
};
static const int g_testMax = sizeof(g_testsName)/sizeof(g_testsName[0]);

View File

@ -264,6 +264,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\..\external\websockets\prebuilt\win32\*.*" "$(Ou
<ClCompile Include="..\Classes\PerformanceTest\PerformanceTest.cpp" />
<ClCompile Include="..\Classes\PerformanceTest\PerformanceTextureTest.cpp" />
<ClCompile Include="..\Classes\PerformanceTest\PerformanceTouchesTest.cpp" />
<ClCompile Include="..\Classes\PerformanceTest\PerformanceCallbackTest.cpp" />
<ClCompile Include="..\Classes\ZwoptexTest\ZwoptexTest.cpp" />
<ClCompile Include="..\Classes\CurlTest\CurlTest.cpp" />
<ClCompile Include="..\Classes\TextInputTest\TextInputTest.cpp" />
@ -445,6 +446,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\..\external\websockets\prebuilt\win32\*.*" "$(Ou
<ClInclude Include="..\Classes\PerformanceTest\PerformanceTest.h" />
<ClInclude Include="..\Classes\PerformanceTest\PerformanceTextureTest.h" />
<ClInclude Include="..\Classes\PerformanceTest\PerformanceTouchesTest.h" />
<ClInclude Include="..\Classes\PerformanceTest\PerformanceCallbackTest.h" />
<ClInclude Include="..\Classes\ZwoptexTest\ZwoptexTest.h" />
<ClInclude Include="..\Classes\CurlTest\CurlTest.h" />
<ClInclude Include="..\Classes\TextInputTest\TextInputTest.h" />

View File

@ -438,6 +438,9 @@
<ClCompile Include="..\Classes\PerformanceTest\PerformanceTouchesTest.cpp">
<Filter>Classes\PerformanceTest</Filter>
</ClCompile>
<ClCompile Include="..\Classes\PerformanceTest\PerformanceCallbackTest.cpp">
<Filter>Classes\PerformanceTest</Filter>
</ClCompile>
<ClCompile Include="..\Classes\ZwoptexTest\ZwoptexTest.cpp">
<Filter>Classes\ZwoptexTest</Filter>
</ClCompile>
@ -953,6 +956,9 @@
<ClInclude Include="..\Classes\PerformanceTest\PerformanceTouchesTest.h">
<Filter>Classes\PerformanceTest</Filter>
</ClInclude>
<ClInclude Include="..\Classes\PerformanceTest\PerformanceCallbackTest.h">
<Filter>Classes\PerformanceTest</Filter>
</ClInclude>
<ClInclude Include="..\Classes\ZwoptexTest\ZwoptexTest.h">
<Filter>Classes\ZwoptexTest</Filter>
</ClInclude>

View File

@ -293,6 +293,7 @@
<ClCompile Include="..\..\..\Classes\PerformanceTest\PerformanceTest.cpp" />
<ClCompile Include="..\..\..\Classes\PerformanceTest\PerformanceTextureTest.cpp" />
<ClCompile Include="..\..\..\Classes\PerformanceTest\PerformanceTouchesTest.cpp" />
<ClCompile Include="..\..\..\Classes\PerformanceTest\PerformanceCallbackTest.cpp" />
<ClCompile Include="..\..\..\Classes\PhysicsTest\PhysicsTest.cpp" />
<ClCompile Include="..\..\..\Classes\ReleasePoolTest\ReleasePoolTest.cpp" />
<ClCompile Include="..\..\..\Classes\RenderTextureTest\RenderTextureTest.cpp" />
@ -501,6 +502,7 @@
<ClInclude Include="..\..\..\Classes\PerformanceTest\PerformanceTest.h" />
<ClInclude Include="..\..\..\Classes\PerformanceTest\PerformanceTextureTest.h" />
<ClInclude Include="..\..\..\Classes\PerformanceTest\PerformanceTouchesTest.h" />
<ClInclude Include="..\..\..\Classes\PerformanceTest\PerformanceCallbackTest.h" />
<ClInclude Include="..\..\..\Classes\PhysicsTest\PhysicsTest.h" />
<ClInclude Include="..\..\..\Classes\ReleasePoolTest\ReleasePoolTest.h" />
<ClInclude Include="..\..\..\Classes\RenderTextureTest\RenderTextureTest.h" />

View File

@ -642,6 +642,9 @@
<ClCompile Include="..\..\..\Classes\PerformanceTest\PerformanceTouchesTest.cpp">
<Filter>Classes\PerformanceTest</Filter>
</ClCompile>
<ClCompile Include="..\..\..\Classes\PerformanceTest\PerformanceCallbackTest.cpp">
<Filter>Classes\PerformanceTest</Filter>
</ClCompile>
<ClCompile Include="..\..\..\Classes\PhysicsTest\PhysicsTest.cpp">
<Filter>Classes\PhysicsTest</Filter>
</ClCompile>
@ -1251,6 +1254,9 @@
<ClInclude Include="..\..\..\Classes\PerformanceTest\PerformanceTouchesTest.h">
<Filter>Classes\PerformanceTest</Filter>
</ClInclude>
<ClInclude Include="..\..\..\Classes\PerformanceTest\PerformanceCallbackTest.h">
<Filter>Classes\PerformanceTest</Filter>
</ClInclude>
<ClInclude Include="..\..\..\Classes\PhysicsTest\PhysicsTest.h">
<Filter>Classes\PhysicsTest</Filter>
</ClInclude>

View File

@ -310,6 +310,7 @@
<ClCompile Include="..\..\Classes\PerformanceTest\PerformanceTest.cpp" />
<ClCompile Include="..\..\Classes\PerformanceTest\PerformanceTextureTest.cpp" />
<ClCompile Include="..\..\Classes\PerformanceTest\PerformanceTouchesTest.cpp" />
<ClCompile Include="..\..\Classes\PerformanceTest\PerformanceCallbackTest.cpp" />
<ClCompile Include="..\..\Classes\ZwoptexTest\ZwoptexTest.cpp" />
<ClCompile Include="..\..\Classes\TextInputTest\TextInputTest.cpp" />
<ClCompile Include="..\..\Classes\UserDefaultTest\UserDefaultTest.cpp" />
@ -505,6 +506,7 @@
<ClInclude Include="..\..\Classes\PerformanceTest\PerformanceTest.h" />
<ClInclude Include="..\..\Classes\PerformanceTest\PerformanceTextureTest.h" />
<ClInclude Include="..\..\Classes\PerformanceTest\PerformanceTouchesTest.h" />
<ClInclude Include="..\..\Classes\PerformanceTest\PerformanceCallbackTest.h" />
<ClInclude Include="..\..\Classes\ZwoptexTest\ZwoptexTest.h" />
<ClInclude Include="..\..\Classes\TextInputTest\TextInputTest.h" />
<ClInclude Include="..\..\Classes\UserDefaultTest\UserDefaultTest.h" />

View File

@ -432,6 +432,9 @@
<ClCompile Include="..\..\Classes\PerformanceTest\PerformanceTouchesTest.cpp">
<Filter>Classes\PerformanceTest</Filter>
</ClCompile>
<ClCompile Include="..\..\Classes\PerformanceTest\PerformanceCallbackTest.cpp">
<Filter>Classes\PerformanceTest</Filter>
</ClCompile>
<ClCompile Include="..\..\Classes\ZwoptexTest\ZwoptexTest.cpp">
<Filter>Classes\ZwoptexTest</Filter>
</ClCompile>
@ -947,6 +950,9 @@
<ClInclude Include="..\..\Classes\PerformanceTest\PerformanceTouchesTest.h">
<Filter>Classes\PerformanceTest</Filter>
</ClInclude>
<ClInclude Include="..\..\Classes\PerformanceTest\PerformanceCallbackTest.h">
<Filter>Classes\PerformanceTest</Filter>
</ClInclude>
<ClInclude Include="..\..\Classes\ZwoptexTest\ZwoptexTest.h">
<Filter>Classes\ZwoptexTest</Filter>
</ClInclude>