Adds 2 new performance tests

Invocation with `for_each()` and using `arrayMakeObjectsPerformSelector`

Signed-off-by: Ricardo Quesada <ricardoquesada@gmail.com>
This commit is contained in:
Ricardo Quesada 2013-08-22 18:21:52 -07:00
parent ddb4219d24
commit 38bfadf7f3
3 changed files with 99 additions and 1 deletions

View File

@ -125,7 +125,7 @@ const char* ProfilingTimer::description() const
{
static char s_desciption[512] = {0};
sprintf(s_desciption, "%s ::\tavg1: %dµ,\tavg2: %dµ,\tmin: %dµ,\tmax: %dµ,\ttotal: %.4fs,\tnr calls: %d", _nameStr.c_str(), _averageTime1, _averageTime2, minTime, maxTime, totalTime/1000000., numberOfCalls);
sprintf(s_desciption, "%s ::\tavg1: %dµ,\tavg2: %dµ,\tmin: %dµ,\tmax: %dµ,\ttotal: %.2fs,\tnr calls: %d", _nameStr.c_str(), _averageTime1, _averageTime2, minTime, maxTime, totalTime/1000000., numberOfCalls);
return s_desciption;
}

View File

@ -33,6 +33,9 @@ static std::function<NodeChildrenMainScene*()> createFunctions[] =
CL(IterateSpriteSheetCArray),
CL(IterateSpriteSheetIterator),
CL(CallFuncsSpriteSheetForEach),
CL(CallFuncsSpriteSheetCMacro),
CL(AddSpriteSheet),
CL(RemoveSpriteSheet),
CL(ReorderSpriteSheet),
@ -364,7 +367,78 @@ const char* IterateSpriteSheetIterator::profilerName()
return "Iterator: begin(), end()";
}
////////////////////////////////////////////////////////
//
// CallFuncsSpriteSheetForEach
//
////////////////////////////////////////////////////////
void CallFuncsSpriteSheetForEach::update(float dt)
{
// iterate using fast enumeration protocol
auto children = batchNode->getChildren();
CC_PROFILER_START(this->profilerName());
std::for_each(std::begin(*children), std::end(*children), [](Object* obj) {
static_cast<Node*>(obj)->getPosition();
});
CC_PROFILER_STOP(this->profilerName());
}
std::string CallFuncsSpriteSheetForEach::title()
{
return "D - 'map' functional call";
}
std::string CallFuncsSpriteSheetForEach::subtitle()
{
return "Using 'std::for_each()'. See console";
}
const char* CallFuncsSpriteSheetForEach::profilerName()
{
static char _name[256];
snprintf(_name, sizeof(_name)-1, "Map: std::for_each(%d)", quantityOfNodes);
return _name;
}
////////////////////////////////////////////////////////
//
// CallFuncsSpriteSheetCMacro
//
////////////////////////////////////////////////////////
void CallFuncsSpriteSheetCMacro::update(float dt)
{
// iterate using fast enumeration protocol
auto children = batchNode->getChildren();
CC_PROFILER_START(this->profilerName());
arrayMakeObjectsPerformSelector(children, getPosition, Node*);
CC_PROFILER_STOP(this->profilerName());
}
std::string CallFuncsSpriteSheetCMacro::title()
{
return "E - 'map' functional call";
}
std::string CallFuncsSpriteSheetCMacro::subtitle()
{
return "Using 'arrayMakeObjectsPerformSelector'. See console";
}
const char* CallFuncsSpriteSheetCMacro::profilerName()
{
static char _name[256];
snprintf(_name, sizeof(_name)-1, "Map: arrayMakeObjectsPerformSelector(%d)", quantityOfNodes);
return _name;
}
////////////////////////////////////////////////////////
//
// AddRemoveSpriteSheet

View File

@ -94,6 +94,30 @@ protected:
#endif
};
///
class CallFuncsSpriteSheetForEach : public IterateSpriteSheet
{
public:
virtual void update(float dt);
virtual std::string title();
virtual std::string subtitle();
virtual const char* profilerName();
};
class CallFuncsSpriteSheetCMacro : public IterateSpriteSheet
{
public:
virtual void update(float dt);
virtual std::string title();
virtual std::string subtitle();
virtual const char* profilerName();
};
///
class AddSpriteSheet : public AddRemoveSpriteSheet
{
public: