mirror of https://github.com/axmolengine/axmol.git
Add Math tests.
This commit is contained in:
parent
44b916ad74
commit
5bb3f1b9c4
|
@ -1048,6 +1048,8 @@
|
|||
FADE78B01B9E88420061590D /* TileMaps in Resources */ = {isa = PBXBuildFile; fileRef = FADE78AC1B9E88420061590D /* TileMaps */; };
|
||||
FADE78B31B9EC0290061590D /* PerformanceCallbackTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FADE78B11B9EC0290061590D /* PerformanceCallbackTest.cpp */; };
|
||||
FADE78B41B9EC0290061590D /* PerformanceCallbackTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FADE78B11B9EC0290061590D /* PerformanceCallbackTest.cpp */; };
|
||||
FADE78B71B9EC6160061590D /* PerformanceMathTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FADE78B51B9EC6160061590D /* PerformanceMathTest.cpp */; };
|
||||
FADE78B81B9EC6160061590D /* PerformanceMathTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FADE78B51B9EC6160061590D /* PerformanceMathTest.cpp */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXContainerItemProxy section */
|
||||
|
@ -2194,6 +2196,8 @@
|
|||
FADE78AC1B9E88420061590D /* TileMaps */ = {isa = PBXFileReference; lastKnownFileType = folder; name = TileMaps; path = "../tests/performance-tests/Resources/TileMaps"; sourceTree = "<group>"; };
|
||||
FADE78B11B9EC0290061590D /* PerformanceCallbackTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PerformanceCallbackTest.cpp; sourceTree = "<group>"; };
|
||||
FADE78B21B9EC0290061590D /* PerformanceCallbackTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PerformanceCallbackTest.h; sourceTree = "<group>"; };
|
||||
FADE78B51B9EC6160061590D /* PerformanceMathTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PerformanceMathTest.cpp; sourceTree = "<group>"; };
|
||||
FADE78B61B9EC6160061590D /* PerformanceMathTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PerformanceMathTest.h; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
|
@ -4811,6 +4815,8 @@
|
|||
FADE78981B9D5C640061590D /* PerformanceEventDispatcherTest.h */,
|
||||
FADE78931B9C42E80061590D /* PerformanceLabelTest.cpp */,
|
||||
FADE78941B9C42E80061590D /* PerformanceLabelTest.h */,
|
||||
FADE78B51B9EC6160061590D /* PerformanceMathTest.cpp */,
|
||||
FADE78B61B9EC6160061590D /* PerformanceMathTest.h */,
|
||||
FADE786D1B9451540061590D /* PerformanceNodeChildrenTest.cpp */,
|
||||
FADE786E1B9451540061590D /* PerformanceNodeChildrenTest.h */,
|
||||
FADE78711B9572990061590D /* PerformanceParticleTest.cpp */,
|
||||
|
@ -6307,6 +6313,7 @@
|
|||
FA94B2451B90497E0074B261 /* controller.cpp in Sources */,
|
||||
FADE788E1B96D0710061590D /* PerformanceSpriteTest.cpp in Sources */,
|
||||
FA94B2431B90497E0074B261 /* BaseTest.cpp in Sources */,
|
||||
FADE78B81B9EC6160061590D /* PerformanceMathTest.cpp in Sources */,
|
||||
FA94B23B1B9045160074B261 /* PerformanceAllocTest.cpp in Sources */,
|
||||
FADE78741B9572990061590D /* PerformanceParticleTest.cpp in Sources */,
|
||||
FADE789A1B9D5C640061590D /* PerformanceEventDispatcherTest.cpp in Sources */,
|
||||
|
@ -6342,6 +6349,7 @@
|
|||
FADE78991B9D5C640061590D /* PerformanceEventDispatcherTest.cpp in Sources */,
|
||||
FADE78731B9572990061590D /* PerformanceParticleTest.cpp in Sources */,
|
||||
FA94B2441B90497E0074B261 /* controller.cpp in Sources */,
|
||||
FADE78B71B9EC6160061590D /* PerformanceMathTest.cpp in Sources */,
|
||||
FADE78951B9C42E80061590D /* PerformanceLabelTest.cpp in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
|
|
|
@ -0,0 +1,166 @@
|
|||
#include "PerformanceMathTest.h"
|
||||
#include "Profile.h"
|
||||
|
||||
USING_NS_CC;
|
||||
|
||||
// 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 const int K_INFO_LOOP_TAG = 1581;
|
||||
|
||||
static int autoTestLoopCounts[] = {
|
||||
10000, 20000, 30000
|
||||
};
|
||||
|
||||
PerformceMathTests::PerformceMathTests()
|
||||
{
|
||||
ADD_TEST_CASE(PerformanceMathLayer1);
|
||||
ADD_TEST_CASE(PerformanceMathLayer2);
|
||||
}
|
||||
|
||||
void PerformanceMathLayer::onEnter()
|
||||
{
|
||||
TestCase::onEnter();
|
||||
|
||||
_loopCount = 10000;
|
||||
_stepCount = 10000;
|
||||
|
||||
CC_PROFILER_PURGE_ALL();
|
||||
|
||||
if (isAutoTesting()) {
|
||||
autoTestIndex = 0;
|
||||
_loopCount = autoTestLoopCounts[autoTestIndex];
|
||||
Profile::getInstance()->testCaseBegin("MathTest",
|
||||
genStrVector("Type", "LoopCount", nullptr),
|
||||
genStrVector("Avg", "Min", "Max", nullptr));
|
||||
}
|
||||
|
||||
auto s = Director::getInstance()->getWinSize();
|
||||
|
||||
MenuItemFont::setFontSize(65);
|
||||
auto decrease = MenuItemFont::create(" - ", CC_CALLBACK_1(PerformanceMathLayer::subLoopCount, this));
|
||||
decrease->setColor(Color3B(0,200,20));
|
||||
auto increase = MenuItemFont::create(" + ", CC_CALLBACK_1(PerformanceMathLayer::addLoopCount, this));
|
||||
increase->setColor(Color3B(0,200,20));
|
||||
|
||||
auto menu = Menu::create(decrease, increase, nullptr);
|
||||
menu->alignItemsHorizontally();
|
||||
menu->setPosition(Vec2(s.width/2, s.height/2));
|
||||
addChild(menu, 1);
|
||||
|
||||
auto infoLabel = Label::createWithTTF("0", "fonts/Marker Felt.ttf", 30);
|
||||
infoLabel->setColor(Color3B(0,200,20));
|
||||
infoLabel->setPosition(Vec2(s.width/2, s.height/2 + 40));
|
||||
addChild(infoLabel, 1, K_INFO_LOOP_TAG);
|
||||
updateLoopLabel();
|
||||
|
||||
getScheduler()->schedule(schedule_selector(PerformanceMathLayer::doPerformanceTest), this, 0.0f, false);
|
||||
getScheduler()->schedule(schedule_selector(PerformanceMathLayer::dumpProfilerInfo), this, 2, false);
|
||||
|
||||
}
|
||||
|
||||
void PerformanceMathLayer::addLoopCount(Ref *sender)
|
||||
{
|
||||
_loopCount += _stepCount;
|
||||
CC_PROFILER_PURGE_ALL();
|
||||
updateLoopLabel();
|
||||
}
|
||||
|
||||
void PerformanceMathLayer::subLoopCount(Ref *sender)
|
||||
{
|
||||
_loopCount -= _stepCount;
|
||||
_loopCount = std::max(_loopCount, 0);
|
||||
CC_PROFILER_PURGE_ALL();
|
||||
updateLoopLabel();
|
||||
}
|
||||
|
||||
void PerformanceMathLayer::updateLoopLabel()
|
||||
{
|
||||
auto infoLabel = (Label *) getChildByTag(K_INFO_LOOP_TAG);
|
||||
char str[16] = {0};
|
||||
sprintf(str, "%u", _loopCount);
|
||||
infoLabel->setString(str);
|
||||
|
||||
}
|
||||
|
||||
void PerformanceMathLayer::dumpProfilerInfo(float dt)
|
||||
{
|
||||
CC_PROFILER_DISPLAY_TIMERS();
|
||||
|
||||
if (this->isAutoTesting()) {
|
||||
// record the test result to class Profile
|
||||
auto timer = Profiler::getInstance()->_activeTimers.at(_profileName);
|
||||
auto numStr = genStr("%d", _loopCount);
|
||||
auto avgStr = genStr("%ldµ", timer->_averageTime2);
|
||||
auto minStr = genStr("%ldµ", timer->minTime);
|
||||
auto maxStr = genStr("%ldµ", timer->maxTime);
|
||||
Profile::getInstance()->addTestResult(genStrVector(_profileName.c_str(), numStr.c_str(), nullptr),
|
||||
genStrVector(avgStr.c_str(), minStr.c_str(), maxStr.c_str(), nullptr));
|
||||
|
||||
auto testsSize = sizeof(autoTestLoopCounts)/sizeof(int);
|
||||
if (autoTestIndex >= (testsSize - 1)) {
|
||||
this->setAutoTesting(false);
|
||||
Profile::getInstance()->testCaseEnd();
|
||||
}
|
||||
else
|
||||
{
|
||||
// update the auto test index
|
||||
autoTestIndex++;
|
||||
_loopCount = autoTestLoopCounts[autoTestIndex];
|
||||
updateLoopLabel();
|
||||
CC_PROFILER_PURGE_ALL();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PerformanceMathLayer1::doPerformanceTest(float dt)
|
||||
{
|
||||
Mat4 dst = Mat4::IDENTITY;
|
||||
Mat4 src;
|
||||
Mat4::createRotation(Vec3(1,1,1), 10, &src);
|
||||
CC_PROFILER_START(_profileName.c_str());
|
||||
for (int i = 0; i < _loopCount; ++i)
|
||||
{
|
||||
dst = dst * src;
|
||||
}
|
||||
CC_PROFILER_STOP(_profileName.c_str());
|
||||
|
||||
}
|
||||
|
||||
void PerformanceMathLayer2::doPerformanceTest(float dt)
|
||||
{
|
||||
Vec4 dst(1,3,4,1);
|
||||
Mat4 src;
|
||||
Mat4::createRotation(Vec3(1,1,1), 10, &src);
|
||||
CC_PROFILER_START(_profileName.c_str());
|
||||
for (int i = 0; i < _loopCount; ++i)
|
||||
{
|
||||
dst = src * dst;
|
||||
}
|
||||
CC_PROFILER_STOP(_profileName.c_str());
|
||||
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
#ifndef __PERFORMANCE_MATH_TEST_H__
|
||||
#define __PERFORMANCE_MATH_TEST_H__
|
||||
|
||||
#include "BaseTest.h"
|
||||
|
||||
DEFINE_TEST_SUITE(PerformceMathTests);
|
||||
|
||||
class PerformanceMathLayer : public TestCase
|
||||
{
|
||||
public:
|
||||
PerformanceMathLayer()
|
||||
: _loopCount(1000)
|
||||
, _stepCount(500)
|
||||
, _profileName("")
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
virtual void onEnter() override;
|
||||
|
||||
virtual std::string title() const override{ return "Math Performance Test"; }
|
||||
virtual std::string subtitle() const override{ return "PerformanceMathLayer subTitle"; }
|
||||
|
||||
void addLoopCount(cocos2d::Ref* sender);
|
||||
void subLoopCount(cocos2d::Ref* sender);
|
||||
protected:
|
||||
virtual void doPerformanceTest(float dt) {};
|
||||
|
||||
void dumpProfilerInfo(float dt);
|
||||
void updateLoopLabel();
|
||||
protected:
|
||||
int autoTestIndex;
|
||||
int _loopCount;
|
||||
int _stepCount;
|
||||
std::string _profileName;
|
||||
};
|
||||
|
||||
class PerformanceMathLayer1 : public PerformanceMathLayer
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(PerformanceMathLayer1);
|
||||
|
||||
PerformanceMathLayer1()
|
||||
{
|
||||
_profileName = "Mat4*Mat4";
|
||||
}
|
||||
|
||||
virtual void doPerformanceTest(float dt) override;
|
||||
|
||||
virtual std::string subtitle() const override{ return "Mat4 * Mat4"; }
|
||||
private:
|
||||
};
|
||||
|
||||
class PerformanceMathLayer2 : public PerformanceMathLayer
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(PerformanceMathLayer2);
|
||||
|
||||
PerformanceMathLayer2()
|
||||
{
|
||||
_profileName = "MatTransformVec4";
|
||||
}
|
||||
|
||||
virtual void doPerformanceTest(float dt) override;
|
||||
|
||||
virtual std::string subtitle() const override{ return "Mat4 TransformVec4"; }
|
||||
|
||||
};
|
||||
|
||||
#endif //__PERFORMANCE_MATH_TEST_H__
|
|
@ -30,6 +30,7 @@ public:
|
|||
addTest("EventDispatcher Tests", []() { return new PerformceEventDispatcherTests(); });
|
||||
addTest("Scenario Tests", []() { return new PerformceScenarioTests(); });
|
||||
addTest("Callback Tests", []() { return new PerformceCallbackTests(); });
|
||||
addTest("Math Tests", []() { return new PerformceMathTests(); });
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -12,5 +12,6 @@
|
|||
#include "PerformanceEventDispatcherTest.h"
|
||||
#include "PerformanceScenarioTest.h"
|
||||
#include "PerformanceCallbackTest.h"
|
||||
#include "PerformanceMathTest.h"
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue