More accurate test

Name is recalculated. No time is "wasted" in calculating it.

And `Visit` test uses `Node` objects instead of `Sprite`s. So `draw` is not taken into account, just the visit.

Signed-off-by: Ricardo Quesada <ricardoquesada@gmail.com>
This commit is contained in:
Ricardo Quesada 2013-08-28 18:32:45 -07:00
parent 530a0119ae
commit c04409b6d5
2 changed files with 54 additions and 41 deletions

View File

@ -149,7 +149,7 @@ void NodeChildrenMainScene::initWithQuantityOfNodes(unsigned int nNodes)
updateQuantityLabel(); updateQuantityLabel();
updateQuantityOfNodes(); updateQuantityOfNodes();
updateProfilerName();
CC_PROFILER_PURGE_ALL(); CC_PROFILER_PURGE_ALL();
}); });
decrease->setColor(Color3B(0,200,20)); decrease->setColor(Color3B(0,200,20));
@ -160,7 +160,7 @@ void NodeChildrenMainScene::initWithQuantityOfNodes(unsigned int nNodes)
updateQuantityLabel(); updateQuantityLabel();
updateQuantityOfNodes(); updateQuantityOfNodes();
updateProfilerName();
CC_PROFILER_PURGE_ALL(); CC_PROFILER_PURGE_ALL();
}); });
increase->setColor(Color3B(0,200,20)); increase->setColor(Color3B(0,200,20));
@ -181,6 +181,7 @@ void NodeChildrenMainScene::initWithQuantityOfNodes(unsigned int nNodes)
updateQuantityLabel(); updateQuantityLabel();
updateQuantityOfNodes(); updateQuantityOfNodes();
updateProfilerName();
} }
std::string NodeChildrenMainScene::title() std::string NodeChildrenMainScene::title()
@ -206,6 +207,17 @@ void NodeChildrenMainScene::updateQuantityLabel()
} }
} }
const char * NodeChildrenMainScene::profilerName()
{
return _profilerName;
}
void NodeChildrenMainScene::updateProfilerName()
{
snprintf(_profilerName, sizeof(_profilerName)-1, "%s(%d)", testName(), quantityOfNodes);
}
//////////////////////////////////////////////////////// ////////////////////////////////////////////////////////
// //
// IterateSpriteSheet // IterateSpriteSheet
@ -255,7 +267,7 @@ void IterateSpriteSheet::initWithQuantityOfNodes(unsigned int nNodes)
scheduleUpdate(); scheduleUpdate();
} }
const char* IterateSpriteSheet::profilerName() const char* IterateSpriteSheet::testName()
{ {
return "none"; return "none";
} }
@ -292,7 +304,7 @@ std::string IterateSpriteSheetForLoop::subtitle()
return "Iterate children using C++11 range-based for loop. See console"; return "Iterate children using C++11 range-based for loop. See console";
} }
const char* IterateSpriteSheetForLoop::profilerName() const char* IterateSpriteSheetForLoop::testName()
{ {
return "Iterator: C++11 for loop"; return "Iterator: C++11 for loop";
} }
@ -330,7 +342,7 @@ std::string IterateSpriteSheetCArray::subtitle()
return "Iterate children using C Array API. See console"; return "Iterate children using C Array API. See console";
} }
const char* IterateSpriteSheetCArray::profilerName() const char* IterateSpriteSheetCArray::testName()
{ {
return "Iterator: CC_ARRAY_FOREACH"; return "Iterator: CC_ARRAY_FOREACH";
} }
@ -368,7 +380,7 @@ std::string IterateSpriteSheetIterator::subtitle()
return "Iterate children using begin() / end(). See console"; return "Iterate children using begin() / end(). See console";
} }
const char* IterateSpriteSheetIterator::profilerName() const char* IterateSpriteSheetIterator::testName()
{ {
return "Iterator: begin(), end()"; return "Iterator: begin(), end()";
} }
@ -409,12 +421,9 @@ std::string CallFuncsSpriteSheetForEach::subtitle()
return "Using 'std::for_each()'. See console"; return "Using 'std::for_each()'. See console";
} }
const char* CallFuncsSpriteSheetForEach::profilerName() const char* CallFuncsSpriteSheetForEach::testName()
{ {
static char _name[256]; return "Map: std::for_each";
snprintf(_name, sizeof(_name)-1, "Map: std::for_each(%d)", quantityOfNodes);
return _name;
} }
//////////////////////////////////////////////////////// ////////////////////////////////////////////////////////
@ -445,11 +454,9 @@ std::string CallFuncsSpriteSheetCMacro::subtitle()
return "Using 'arrayMakeObjectsPerformSelector'. See console"; return "Using 'arrayMakeObjectsPerformSelector'. See console";
} }
const char* CallFuncsSpriteSheetCMacro::profilerName() const char* CallFuncsSpriteSheetCMacro::testName()
{ {
static char _name[256]; return "Map: arrayMakeObjectsPerformSelector";
snprintf(_name, sizeof(_name)-1, "Map: arrayMakeObjectsPerformSelector(%d)", quantityOfNodes);
return _name;
} }
//////////////////////////////////////////////////////// ////////////////////////////////////////////////////////
// //
@ -499,7 +506,7 @@ void AddRemoveSpriteSheet::updateQuantityOfNodes()
currentQuantityOfNodes = quantityOfNodes; currentQuantityOfNodes = quantityOfNodes;
} }
const char* AddRemoveSpriteSheet::profilerName() const char* AddRemoveSpriteSheet::testName()
{ {
return "none"; return "none";
} }
@ -562,7 +569,7 @@ std::string AddSpriteSheet::subtitle()
return "Adds %10 of total sprites with random z. See console"; return "Adds %10 of total sprites with random z. See console";
} }
const char* AddSpriteSheet::profilerName() const char* AddSpriteSheet::testName()
{ {
return "add sprites"; return "add sprites";
} }
@ -627,7 +634,7 @@ std::string GetSpriteSheet::subtitle()
return "Get sprites using getChildByTag(). See console"; return "Get sprites using getChildByTag(). See console";
} }
const char* GetSpriteSheet::profilerName() const char* GetSpriteSheet::testName()
{ {
return "get sprites"; return "get sprites";
} }
@ -683,7 +690,7 @@ std::string RemoveSpriteSheet::subtitle()
return "Remove %10 of total sprites placed randomly. See console"; return "Remove %10 of total sprites placed randomly. See console";
} }
const char* RemoveSpriteSheet::profilerName() const char* RemoveSpriteSheet::testName()
{ {
return "remove sprites"; return "remove sprites";
} }
@ -746,7 +753,7 @@ std::string ReorderSpriteSheet::subtitle()
return "Reorder %10 of total sprites placed randomly. See console"; return "Reorder %10 of total sprites placed randomly. See console";
} }
const char* ReorderSpriteSheet::profilerName() const char* ReorderSpriteSheet::testName()
{ {
return "reorder sprites"; return "reorder sprites";
} }
@ -811,7 +818,7 @@ std::string SortAllChildrenSpriteSheet::subtitle()
return "Calls sortOfChildren(). See console"; return "Calls sortOfChildren(). See console";
} }
const char* SortAllChildrenSpriteSheet::profilerName() const char* SortAllChildrenSpriteSheet::testName()
{ {
return "sort all children"; return "sort all children";
} }
@ -837,11 +844,11 @@ void VisitSceneGraph::updateQuantityOfNodes()
{ {
for(int i = 0; i < (quantityOfNodes-currentQuantityOfNodes); i++) for(int i = 0; i < (quantityOfNodes-currentQuantityOfNodes); i++)
{ {
auto sprite = Sprite::create("Images/spritesheet1.png", Rect(0, 0, 32, 32)); auto node = Node::create();
this->addChild(sprite); this->addChild(node);
sprite->setVisible(true); node->setVisible(true);
sprite->setPosition(Point(-1000,-1000)); node->setPosition(Point(-1000,-1000));
sprite->setTag(1000 + currentQuantityOfNodes + i ); node->setTag(1000 + currentQuantityOfNodes + i );
} }
} }
@ -873,7 +880,7 @@ std::string VisitSceneGraph::subtitle()
return "calls visit() on scene graph. See console"; return "calls visit() on scene graph. See console";
} }
const char* VisitSceneGraph::profilerName() const char* VisitSceneGraph::testName()
{ {
return "visit scene graph"; return "visit scene graph";
} }

View File

@ -23,13 +23,19 @@ public:
virtual std::string title(); virtual std::string title();
virtual std::string subtitle(); virtual std::string subtitle();
virtual void updateQuantityOfNodes() = 0; virtual void updateQuantityOfNodes() = 0;
virtual const char* profilerName() = 0;
const char* profilerName();
void updateProfilerName();
// for the profiler
virtual const char* testName() = 0;
void updateQuantityLabel(); void updateQuantityLabel();
int getQuantityOfNodes() { return quantityOfNodes; } int getQuantityOfNodes() { return quantityOfNodes; }
protected: protected:
char _profilerName[256];
int lastRenderedCount; int lastRenderedCount;
int quantityOfNodes; int quantityOfNodes;
int currentQuantityOfNodes; int currentQuantityOfNodes;
@ -42,7 +48,7 @@ public:
virtual void updateQuantityOfNodes(); virtual void updateQuantityOfNodes();
virtual void initWithQuantityOfNodes(unsigned int nNodes); virtual void initWithQuantityOfNodes(unsigned int nNodes);
virtual void update(float dt) = 0; virtual void update(float dt) = 0;
virtual const char* profilerName(); virtual const char* testName();
protected: protected:
SpriteBatchNode *batchNode; SpriteBatchNode *batchNode;
@ -55,7 +61,7 @@ public:
virtual std::string title(); virtual std::string title();
virtual std::string subtitle(); virtual std::string subtitle();
virtual const char* profilerName(); virtual const char* testName();
}; };
class IterateSpriteSheetIterator : public IterateSpriteSheet class IterateSpriteSheetIterator : public IterateSpriteSheet
@ -65,7 +71,7 @@ public:
virtual std::string title(); virtual std::string title();
virtual std::string subtitle(); virtual std::string subtitle();
virtual const char* profilerName(); virtual const char* testName();
}; };
class IterateSpriteSheetCArray : public IterateSpriteSheet class IterateSpriteSheetCArray : public IterateSpriteSheet
@ -75,7 +81,7 @@ public:
virtual std::string title(); virtual std::string title();
virtual std::string subtitle(); virtual std::string subtitle();
virtual const char* profilerName(); virtual const char* testName();
}; };
class AddRemoveSpriteSheet : public NodeChildrenMainScene class AddRemoveSpriteSheet : public NodeChildrenMainScene
@ -85,7 +91,7 @@ public:
virtual void updateQuantityOfNodes(); virtual void updateQuantityOfNodes();
virtual void initWithQuantityOfNodes(unsigned int nNodes); virtual void initWithQuantityOfNodes(unsigned int nNodes);
virtual void update(float dt) = 0; virtual void update(float dt) = 0;
virtual const char* profilerName(); virtual const char* testName();
protected: protected:
SpriteBatchNode *batchNode; SpriteBatchNode *batchNode;
@ -104,7 +110,7 @@ public:
virtual std::string title(); virtual std::string title();
virtual std::string subtitle(); virtual std::string subtitle();
virtual const char* profilerName(); virtual const char* testName();
}; };
class CallFuncsSpriteSheetCMacro : public IterateSpriteSheet class CallFuncsSpriteSheetCMacro : public IterateSpriteSheet
@ -114,7 +120,7 @@ public:
virtual std::string title(); virtual std::string title();
virtual std::string subtitle(); virtual std::string subtitle();
virtual const char* profilerName(); virtual const char* testName();
}; };
/// ///
@ -126,7 +132,7 @@ public:
virtual std::string title(); virtual std::string title();
virtual std::string subtitle(); virtual std::string subtitle();
virtual const char* profilerName(); virtual const char* testName();
}; };
class GetSpriteSheet : public AddRemoveSpriteSheet class GetSpriteSheet : public AddRemoveSpriteSheet
@ -136,7 +142,7 @@ public:
virtual std::string title(); virtual std::string title();
virtual std::string subtitle(); virtual std::string subtitle();
virtual const char* profilerName(); virtual const char* testName();
}; };
class RemoveSpriteSheet : public AddRemoveSpriteSheet class RemoveSpriteSheet : public AddRemoveSpriteSheet
@ -146,7 +152,7 @@ public:
virtual std::string title(); virtual std::string title();
virtual std::string subtitle(); virtual std::string subtitle();
virtual const char* profilerName(); virtual const char* testName();
}; };
class ReorderSpriteSheet : public AddRemoveSpriteSheet class ReorderSpriteSheet : public AddRemoveSpriteSheet
@ -156,7 +162,7 @@ public:
virtual std::string title(); virtual std::string title();
virtual std::string subtitle(); virtual std::string subtitle();
virtual const char* profilerName(); virtual const char* testName();
}; };
class SortAllChildrenSpriteSheet : public AddRemoveSpriteSheet class SortAllChildrenSpriteSheet : public AddRemoveSpriteSheet
@ -166,7 +172,7 @@ public:
virtual std::string title(); virtual std::string title();
virtual std::string subtitle(); virtual std::string subtitle();
virtual const char* profilerName(); virtual const char* testName();
}; };
class VisitSceneGraph : public NodeChildrenMainScene class VisitSceneGraph : public NodeChildrenMainScene
@ -178,7 +184,7 @@ public:
void updateQuantityOfNodes() override; void updateQuantityOfNodes() override;
virtual std::string title() override; virtual std::string title() override;
virtual std::string subtitle() override; virtual std::string subtitle() override;
virtual const char* profilerName() override; virtual const char* testName() override;
}; };
void runNodeChildrenTest(); void runNodeChildrenTest();