//////////////////////////////////////////////////////// // // ReorderSpriteSheet // //////////////////////////////////////////////////////// void ReorderSpriteSheet::update(float dt) { //srandom(0); // 100 percent int totalToAdd = currentQuantityOfNodes * 1; if( totalToAdd > 0 ) { Sprite **sprites = new Sprite*[totalToAdd]; // Don't include the sprite creation time as part of the profiling for(int i=0; i<totalToAdd; i++) { sprites[i] = Sprite::createWithTexture(batchNode->getTexture(), Rect(0,0,32,32)); } // add them with random Z (very important!) for( int i=0; i < totalToAdd;i++ ) { batchNode->addChild( sprites[i], CCRANDOM_MINUS1_1() * 50, kTagBase+i); } batchNode->sortAllChildren(); // reorder them CC_PROFILER_START( this->profilerName() ); for( int i=0;i < totalToAdd;i++) { batchNode->reorderChild(sprites[i], CCRANDOM_MINUS1_1() * 50); } CC_PROFILER_STOP( this->profilerName() ); // remove them for( int i=0;i < totalToAdd;i++) { batchNode->removeChild( sprites[i], true); } delete [] sprites; } }
//////////////////////////////////////////////////////// // // AddSprite // //////////////////////////////////////////////////////// void AddSprite::update(float dt) { // reset seed //srandom(0); // 100 percent int totalToAdd = currentQuantityOfNodes * 1; if( totalToAdd > 0 ) { Sprite **sprites = new (std::nothrow) Sprite*[totalToAdd]; int *zs = new int[totalToAdd]; // Don't include the sprite creation time and random as part of the profiling for(int i=0; i<totalToAdd; i++) { sprites[i] = Sprite::createWithTexture(batchNode->getTexture(), Rect(0,0,32,32)); zs[i] = CCRANDOM_MINUS1_1() * 50; } // add them with random Z (very important!) CC_PROFILER_START( this->profilerName() ); for( int i=0; i < totalToAdd;i++ ) { this->addChild( sprites[i], zs[i], kTagBase+i); } CC_PROFILER_STOP(this->profilerName()); batchNode->sortAllChildren(); // remove them for( int i=0;i < totalToAdd;i++) { this->removeChild( sprites[i], true); } delete [] sprites; delete [] zs; } }
void IsometryNode::draw(void) { CC_PROFILER_START("CCSpriteBatchNode - draw"); // Optimization: Fast Dispatch /*if( m_pobTextureAtlas->getTotalQuads() == 0 ) { return; }*/ CC_NODE_DRAW_SETUP(); arrayMakeObjectsPerformSelector(m_pChildren, updateTransform, CCSprite*); //ccGLBlendFunc( m_blendFunc.src, m_blendFunc.dst ); //m_pobTextureAtlas->drawQuads(); Process(); CC_PROFILER_STOP("CCSpriteBatchNode - draw"); }
void KeyboardEventDispatchingPerfTest::generateTestFunctions() { TestFunction testFunctions[] = { { "keyboard-scenegraph", [=](){ auto dispatcher = Director::getInstance()->getEventDispatcher(); if (_quantityOfNodes != _lastRenderedCount) { auto listener = EventListenerKeyboard::create(); listener->onKeyPressed = [](EventKeyboard::KeyCode keyCode, Event* event){}; listener->onKeyReleased = [](EventKeyboard::KeyCode keyCode, Event* event){}; // Create new nodes listen to keyboard event for (int i = 0; i < this->_quantityOfNodes; ++i) { auto node = Node::create(); node->setTag(1000 + i); this->addChild(node); this->_nodes.push_back(node); dispatcher->addEventListenerWithSceneGraphPriority(listener->clone(), node); } _lastRenderedCount = _quantityOfNodes; } EventKeyboard event(EventKeyboard::KeyCode::KEY_RETURN, true); CC_PROFILER_START(this->profilerName()); dispatcher->dispatchEvent(&event); CC_PROFILER_STOP(this->profilerName()); } } , { "keyboard-fixed", [=](){ auto dispatcher = Director::getInstance()->getEventDispatcher(); if (_quantityOfNodes != _lastRenderedCount) { auto listener = EventListenerKeyboard::create(); listener->onKeyPressed = [](EventKeyboard::KeyCode keyCode, Event* event){}; listener->onKeyReleased = [](EventKeyboard::KeyCode keyCode, Event* event){}; for (int i = 0; i < this->_quantityOfNodes; ++i) { auto l = listener->clone(); this->_fixedPriorityListeners.push_back(l); dispatcher->addEventListenerWithFixedPriority(l, i+1); } _lastRenderedCount = _quantityOfNodes; } EventKeyboard event(EventKeyboard::KeyCode::KEY_RETURN, true); CC_PROFILER_START(this->profilerName()); dispatcher->dispatchEvent(&event); CC_PROFILER_STOP(this->profilerName()); } } , }; for (const auto& func : testFunctions) { _testFunctions.push_back(func); } }
void TouchEventDispatchingPerfTest::generateTestFunctions() { TestFunction testFunctions[] = { { "OneByOne-scenegraph", [=](){ auto dispatcher = Director::getInstance()->getEventDispatcher(); if (_quantityOfNodes != _lastRenderedCount) { auto listener = EventListenerTouchOneByOne::create(); listener->onTouchBegan = [](Touch* touch, Event* event){ return false; }; listener->onTouchMoved = [](Touch* touch, Event* event){}; listener->onTouchEnded = [](Touch* touch, Event* event){}; // Create new touchable nodes for (int i = 0; i < this->_quantityOfNodes; ++i) { auto node = Node::create(); node->setTag(1000 + i); this->addChild(node); this->_nodes.push_back(node); dispatcher->addEventListenerWithSceneGraphPriority(listener->clone(), node); } _lastRenderedCount = _quantityOfNodes; } Size size = Director::getInstance()->getWinSize(); EventTouch touchEvent; touchEvent.setEventCode(EventTouch::EventCode::BEGAN); std::vector<Touch*> touches; for (int i = 0; i < 4; ++i) { Touch* touch = new (std::nothrow) Touch(); touch->autorelease(); touch->setTouchInfo(i, rand() % 200, rand() % 200); touches.push_back(touch); } touchEvent.setTouches(touches); CC_PROFILER_START(this->profilerName()); dispatcher->dispatchEvent(&touchEvent); CC_PROFILER_STOP(this->profilerName()); } } , { "OneByOne-fixed", [=](){ auto dispatcher = Director::getInstance()->getEventDispatcher(); if (_quantityOfNodes != _lastRenderedCount) { auto listener = EventListenerTouchOneByOne::create(); listener->onTouchBegan = [](Touch* touch, Event* event){ return false; }; listener->onTouchMoved = [](Touch* touch, Event* event){}; listener->onTouchEnded = [](Touch* touch, Event* event){}; for (int i = 0; i < this->_quantityOfNodes; ++i) { auto l = listener->clone(); this->_fixedPriorityListeners.push_back(l); dispatcher->addEventListenerWithFixedPriority(l, i+1); } _lastRenderedCount = _quantityOfNodes; } Size size = Director::getInstance()->getWinSize(); EventTouch touchEvent; touchEvent.setEventCode(EventTouch::EventCode::BEGAN); std::vector<Touch*> touches; for (int i = 0; i < 4; ++i) { Touch* touch = new (std::nothrow) Touch(); touch->autorelease(); touch->setTouchInfo(i, rand() % 200, rand() % 200); touches.push_back(touch); } touchEvent.setTouches(touches); CC_PROFILER_START(this->profilerName()); dispatcher->dispatchEvent(&touchEvent); CC_PROFILER_STOP(this->profilerName()); } } , { "AllAtOnce-scenegraph", [=](){ auto dispatcher = Director::getInstance()->getEventDispatcher(); if (_quantityOfNodes != _lastRenderedCount) { auto listener = EventListenerTouchAllAtOnce::create(); listener->onTouchesBegan = [](const std::vector<Touch*> touches, Event* event){}; listener->onTouchesMoved = [](const std::vector<Touch*> touches, Event* event){}; listener->onTouchesEnded = [](const std::vector<Touch*> touches, Event* event){}; // Create new touchable nodes for (int i = 0; i < this->_quantityOfNodes; ++i) { auto node = Node::create(); node->setTag(1000 + i); this->addChild(node); this->_nodes.push_back(node); dispatcher->addEventListenerWithSceneGraphPriority(listener->clone(), node); } _lastRenderedCount = _quantityOfNodes; } Size size = Director::getInstance()->getWinSize(); EventTouch touchEvent; touchEvent.setEventCode(EventTouch::EventCode::BEGAN); std::vector<Touch*> touches; for (int i = 0; i < 4; ++i) { Touch* touch = new (std::nothrow) Touch(); touch->autorelease(); touch->setTouchInfo(i, rand() % 200, rand() % 200); touches.push_back(touch); } touchEvent.setTouches(touches); CC_PROFILER_START(this->profilerName()); dispatcher->dispatchEvent(&touchEvent); CC_PROFILER_STOP(this->profilerName()); } } , { "AllAtOnce-fixed", [=](){ auto dispatcher = Director::getInstance()->getEventDispatcher(); if (_quantityOfNodes != _lastRenderedCount) { auto listener = EventListenerTouchAllAtOnce::create(); listener->onTouchesBegan = [](const std::vector<Touch*> touches, Event* event){}; listener->onTouchesMoved = [](const std::vector<Touch*> touches, Event* event){}; listener->onTouchesEnded = [](const std::vector<Touch*> touches, Event* event){}; for (int i = 0; i < this->_quantityOfNodes; ++i) { auto l = listener->clone(); this->_fixedPriorityListeners.push_back(l); dispatcher->addEventListenerWithFixedPriority(l, i+1); } _lastRenderedCount = _quantityOfNodes; } Size size = Director::getInstance()->getWinSize(); EventTouch touchEvent; touchEvent.setEventCode(EventTouch::EventCode::BEGAN); std::vector<Touch*> touches; for (int i = 0; i < 4; ++i) { Touch* touch = new (std::nothrow) Touch(); touch->autorelease(); touch->setTouchInfo(i, rand() % 200, rand() % 200); touches.push_back(touch); } touchEvent.setTouches(touches); CC_PROFILER_START(this->profilerName()); dispatcher->dispatchEvent(&touchEvent); CC_PROFILER_STOP(this->profilerName()); } } , { "TouchModeMix-scenegraph", [=](){ auto dispatcher = Director::getInstance()->getEventDispatcher(); if (_quantityOfNodes != _lastRenderedCount) { auto listenerOneByOne = EventListenerTouchOneByOne::create(); listenerOneByOne->onTouchBegan = [](Touch* touch, Event* event){ return false; }; listenerOneByOne->onTouchMoved = [](Touch* touch, Event* event){}; listenerOneByOne->onTouchEnded = [](Touch* touch, Event* event){}; auto listenerAllAtOnce = EventListenerTouchAllAtOnce::create(); listenerAllAtOnce->onTouchesBegan = [](const std::vector<Touch*> touches, Event* event){}; listenerAllAtOnce->onTouchesMoved = [](const std::vector<Touch*> touches, Event* event){}; listenerAllAtOnce->onTouchesEnded = [](const std::vector<Touch*> touches, Event* event){}; int i = 0; // Create new touchable nodes for (; i < this->_quantityOfNodes/2; ++i) { auto node = Node::create(); node->setTag(1000 + i); this->addChild(node); this->_nodes.push_back(node); dispatcher->addEventListenerWithSceneGraphPriority(listenerOneByOne->clone(), node); } for (; i < this->_quantityOfNodes; ++i) { auto node = Node::create(); node->setTag(1000 + i); this->addChild(node); this->_nodes.push_back(node); dispatcher->addEventListenerWithSceneGraphPriority(listenerAllAtOnce->clone(), node); } _lastRenderedCount = _quantityOfNodes; } Size size = Director::getInstance()->getWinSize(); EventTouch touchEvent; touchEvent.setEventCode(EventTouch::EventCode::BEGAN); std::vector<Touch*> touches; for (int i = 0; i < 4; ++i) { Touch* touch = new (std::nothrow) Touch(); touch->autorelease(); touch->setTouchInfo(i, rand() % 200, rand() % 200); touches.push_back(touch); } touchEvent.setTouches(touches); CC_PROFILER_START(this->profilerName()); dispatcher->dispatchEvent(&touchEvent); CC_PROFILER_STOP(this->profilerName()); } } , { "TouchModeMix-fixed", [=](){ auto dispatcher = Director::getInstance()->getEventDispatcher(); if (_quantityOfNodes != _lastRenderedCount) { auto listenerOneByOne = EventListenerTouchOneByOne::create(); listenerOneByOne->onTouchBegan = [](Touch* touch, Event* event){ return false; }; listenerOneByOne->onTouchMoved = [](Touch* touch, Event* event){}; listenerOneByOne->onTouchEnded = [](Touch* touch, Event* event){}; auto listenerAllAtOnce = EventListenerTouchAllAtOnce::create(); listenerAllAtOnce->onTouchesBegan = [](const std::vector<Touch*> touches, Event* event){}; listenerAllAtOnce->onTouchesMoved = [](const std::vector<Touch*> touches, Event* event){}; listenerAllAtOnce->onTouchesEnded = [](const std::vector<Touch*> touches, Event* event){}; int i = 0; for (; i < this->_quantityOfNodes/2; ++i) { auto l = listenerOneByOne->clone(); this->_fixedPriorityListeners.push_back(l); dispatcher->addEventListenerWithFixedPriority(l, i+1); } for (; i < this->_quantityOfNodes; ++i) { auto l = listenerAllAtOnce->clone(); this->_fixedPriorityListeners.push_back(l); dispatcher->addEventListenerWithFixedPriority(l, i+1); } _lastRenderedCount = _quantityOfNodes; } Size size = Director::getInstance()->getWinSize(); EventTouch touchEvent; touchEvent.setEventCode(EventTouch::EventCode::BEGAN); std::vector<Touch*> touches; for (int i = 0; i < 4; ++i) { Touch* touch = new (std::nothrow) Touch(); touch->autorelease(); touch->setTouchInfo(i, rand() % 200, rand() % 200); touches.push_back(touch); } touchEvent.setTouches(touches); CC_PROFILER_START(this->profilerName()); dispatcher->dispatchEvent(&touchEvent); CC_PROFILER_STOP(this->profilerName()); } } , }; for (const auto& func : testFunctions) { _testFunctions.push_back(func); } }
void VisitSceneGraph::update(float dt) { CC_PROFILER_START( this->profilerName() ); this->visit(); CC_PROFILER_STOP( this->profilerName() ); }
void TouchesPerformTest3::onEnter() { PerformBasicLayer::onEnter(); auto s = Director::getInstance()->getWinSize(); // add title auto label = Label::createWithTTF(title().c_str(), "fonts/arial.ttf", 32); addChild(label, 1); label->setPosition(Vec2(s.width/2, s.height-50)); #define TOUCH_PROFILER_NAME "TouchProfileName" #define TOUCHABLE_NODE_NUM 1000 srand((unsigned)time(nullptr)); for (int i = 0; i < TOUCHABLE_NODE_NUM; ++i) { int zorder = rand() % TOUCHABLE_NODE_NUM; auto layer = new (std::nothrow) TouchableLayer(); auto listener = EventListenerTouchOneByOne::create(); listener->onTouchBegan = CC_CALLBACK_2(TouchableLayer::onTouchBegan, layer); listener->onTouchMoved = CC_CALLBACK_2(TouchableLayer::onTouchMoved, layer); listener->onTouchEnded = CC_CALLBACK_2(TouchableLayer::onTouchEnded, layer); listener->onTouchCancelled = CC_CALLBACK_2(TouchableLayer::onTouchCancelled, layer); _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, layer); addChild(layer, zorder); layer->release(); } auto emitEventlabel = Label::createWithSystemFont("Emit Touch Event", "", 24); auto menuItem = MenuItemLabel::create(emitEventlabel, [this](Ref* sender){ CC_PROFILER_PURGE_ALL(); std::vector<Touch*> touches; for (int i = 0; i < EventTouch::MAX_TOUCHES; ++i) { Touch* touch = new (std::nothrow) Touch(); touch->setTouchInfo(i, 10, (i+1) * 10); touches.push_back(touch); } EventTouch event; event.setEventCode(EventTouch::EventCode::BEGAN); event.setTouches(touches); for (int i = 0; i < 100; ++i) { CC_PROFILER_START(TOUCH_PROFILER_NAME); _eventDispatcher->dispatchEvent(&event); CC_PROFILER_STOP(TOUCH_PROFILER_NAME); } CC_PROFILER_DISPLAY_TIMERS(); for (auto& touch : touches) { touch->release(); } }); menuItem->setPosition(Vec2(0, -20)); auto menu = Menu::create(menuItem, nullptr); addChild(menu); }
void ArrayPerfTest::generateTestFunctions() { auto createArray = [this](){ __Array* ret = Array::create(); for( int i=0; i<quantityOfNodes; ++i) { auto node = Node::create(); node->setTag(i); ret->addObject(node); } return ret; }; TestFunction testFunctions[] = { { "addObject", [=](){ __Array* nodeVector = Array::create(); CC_PROFILER_START(this->profilerName()); for( int i=0; i<quantityOfNodes; ++i) nodeVector->addObject(Node::create()); CC_PROFILER_STOP(this->profilerName()); } } , { "insertObject", [=](){ __Array* nodeVector = Array::create(); CC_PROFILER_START(this->profilerName()); for( int i=0; i<quantityOfNodes; ++i) nodeVector->insertObject(Node::create(), 0); CC_PROFILER_STOP(this->profilerName()); } } , { "setObject", [=](){ __Array* nodeVector = createArray(); srand((unsigned)time(nullptr)); ssize_t index = rand() % quantityOfNodes; CC_PROFILER_START(this->profilerName()); for( int i=0; i<quantityOfNodes; ++i) nodeVector->setObject(Node::create(), index); CC_PROFILER_STOP(this->profilerName()); } } , { "getIndexOfObject", [=](){ __Array* nodeVector = createArray(); Ref* objToGet = nodeVector->getObjectAtIndex(quantityOfNodes/3); ssize_t index = 0; CC_PROFILER_START(this->profilerName()); for( int i=0; i<quantityOfNodes; ++i) index = nodeVector->getIndexOfObject(objToGet); CC_PROFILER_STOP(this->profilerName()); // Uses `index` to avoids `getIndex` invoking was optimized in release mode if (index == quantityOfNodes/3) { nodeVector->removeAllObjects(); } } } , { "getObjectAtIndex", [=](){ __Array* nodeVector = createArray(); CC_PROFILER_START(this->profilerName()); for( int i=0; i<quantityOfNodes; ++i) nodeVector->getObjectAtIndex(quantityOfNodes/3); CC_PROFILER_STOP(this->profilerName()); } } , { "containsObject", [=](){ __Array* nodeVector = createArray(); Ref* objToGet = nodeVector->getObjectAtIndex(quantityOfNodes/3); CC_PROFILER_START(this->profilerName()); for( int i=0; i<quantityOfNodes; ++i) nodeVector->containsObject(objToGet); CC_PROFILER_STOP(this->profilerName()); } } , { "removeObject", [=](){ __Array* nodeVector = createArray(); Node** nodes = (Node**)malloc(sizeof(Node*) * quantityOfNodes); for (int i = 0; i < quantityOfNodes; ++i) { nodes[i] = static_cast<Node*>(nodeVector->getObjectAtIndex(i)); } CC_PROFILER_START(this->profilerName()); for( int i=0; i<quantityOfNodes; ++i) nodeVector->removeObject(nodes[i]); CC_PROFILER_STOP(this->profilerName()); CCASSERT(nodeVector->count() == 0, "nodeVector was not empty."); free(nodes); } } , { "removeObjectAtIndex", [=](){ __Array* nodeVector = createArray(); CC_PROFILER_START(this->profilerName()); for( int i=0; i<quantityOfNodes; ++i) nodeVector->removeObjectAtIndex(0); CC_PROFILER_STOP(this->profilerName()); CCASSERT(nodeVector->count() == 0, "nodeVector was not empty."); } } , { "removeAllObjects", [=](){ __Array* nodeVector = createArray(); CC_PROFILER_START(this->profilerName()); for( int i=0; i<quantityOfNodes; ++i) nodeVector->removeAllObjects(); CC_PROFILER_STOP(this->profilerName()); CCASSERT(nodeVector->count() == 0, "nodeVector was not empty."); } } , { "swap by index", [=](){ __Array* nodeVector = createArray(); int swapIndex1 = quantityOfNodes / 3; int swapIndex2 = quantityOfNodes / 3 * 2; CC_PROFILER_START(this->profilerName()); for( int i=0; i<quantityOfNodes; ++i) nodeVector->swap(swapIndex1, swapIndex2); CC_PROFILER_STOP(this->profilerName()); } } , { "swap by object", [=](){ __Array* nodeVector = createArray(); Ref* swapNode1 = nodeVector->getObjectAtIndex(quantityOfNodes / 3); Ref* swapNode2 = nodeVector->getObjectAtIndex(quantityOfNodes / 3 * 2); CC_PROFILER_START(this->profilerName()); for( int i=0; i<quantityOfNodes; ++i) nodeVector->exchangeObject(swapNode1, swapNode2); CC_PROFILER_STOP(this->profilerName()); } } , { "reverseObjects", [=](){ __Array* nodeVector = createArray(); CC_PROFILER_START(this->profilerName()); for( int i=0; i<quantityOfNodes; ++i) nodeVector->reverseObjects(); CC_PROFILER_STOP(this->profilerName()); } } , { "CCARRAY_FOREACH", [=](){ __Array* nodeVector = createArray(); Ref* obj; CC_PROFILER_START(this->profilerName()); CCARRAY_FOREACH(nodeVector, obj) { static_cast<Node*>(obj)->setTag(111); } CC_PROFILER_STOP(this->profilerName()); } } ,
void TemplateVectorPerfTest::generateTestFunctions() { auto createVector = [this](){ Vector<Node*> ret; for( int i=0; i<quantityOfNodes; ++i) { auto node = Node::create(); node->setTag(i); ret.pushBack(node); } return ret; }; TestFunction testFunctions[] = { { "pushBack", [=](){ Vector<Node*> nodeVector; CC_PROFILER_START(this->profilerName()); for( int i=0; i<quantityOfNodes; ++i) nodeVector.pushBack(Node::create()); CC_PROFILER_STOP(this->profilerName()); } } , { "insert", [=](){ Vector<Node*> nodeVector; CC_PROFILER_START(this->profilerName()); for( int i=0; i<quantityOfNodes; ++i) nodeVector.insert(0, Node::create()); CC_PROFILER_STOP(this->profilerName()); } } , { "replace", [=](){ Vector<Node*> nodeVector = createVector(); srand((unsigned)time(nullptr)); ssize_t index = rand() % quantityOfNodes; CC_PROFILER_START(this->profilerName()); for( int i=0; i<quantityOfNodes; ++i) nodeVector.replace(index, Node::create()); CC_PROFILER_STOP(this->profilerName()); } } , { "getIndex", [=](){ Vector<Node*> nodeVector = createVector(); Node* objToGet = nodeVector.at(quantityOfNodes/3); ssize_t index = 0; CC_PROFILER_START(this->profilerName()); for( int i=0; i<quantityOfNodes; ++i) index = nodeVector.getIndex(objToGet); CC_PROFILER_STOP(this->profilerName()); // Uses `index` to avoids `getIndex` invoking was optimized in release mode if (index == quantityOfNodes/3) { nodeVector.clear(); } } } , { "find", [=](){ Vector<Node*> nodeVector = createVector(); Node* objToGet = nodeVector.at(quantityOfNodes/3); Vector<Node*>::iterator iter; CC_PROFILER_START(this->profilerName()); for( int i=0; i<quantityOfNodes; ++i) iter = nodeVector.find(objToGet); CC_PROFILER_STOP(this->profilerName()); // Uses `iter` to avoids `find` invoking was optimized in release mode if (*iter == objToGet) { nodeVector.clear(); } } } , { "at", [=](){ Vector<Node*> nodeVector = createVector(); Node* objToGet = nullptr; CC_PROFILER_START(this->profilerName()); for( int i=0; i<quantityOfNodes; ++i) objToGet = nodeVector.at(quantityOfNodes/3); CC_PROFILER_STOP(this->profilerName()); // Uses `objToGet` to avoids `at` invoking was optimized in release mode if (nodeVector.getIndex(objToGet) == quantityOfNodes/3) { nodeVector.clear(); } } } , { "contains", [=](){ Vector<Node*> nodeVector = createVector(); Node* objToGet = nodeVector.at(quantityOfNodes/3); bool ret = false; CC_PROFILER_START(this->profilerName()); for( int i=0; i<quantityOfNodes; ++i) ret = nodeVector.contains(objToGet); CC_PROFILER_STOP(this->profilerName()); // Uses `ret` to avoids `contains` invoking was optimized in release mode if (ret) { nodeVector.clear(); } } } , { "eraseObject", [=](){ Vector<Node*> nodeVector = createVector(); Node** nodes = (Node**)malloc(sizeof(Node*) * quantityOfNodes); for (int i = 0; i < quantityOfNodes; ++i) { nodes[i] = nodeVector.at(i); } CC_PROFILER_START(this->profilerName()); for( int i=0; i<quantityOfNodes; ++i) nodeVector.eraseObject(nodes[i]); CC_PROFILER_STOP(this->profilerName()); CCASSERT(nodeVector.empty(), "nodeVector was not empty."); free(nodes); } } , { "erase", [=](){ Vector<Node*> nodeVector = createVector(); CC_PROFILER_START(this->profilerName()); for( int i=0; i<quantityOfNodes; ++i) nodeVector.erase(nodeVector.begin()); CC_PROFILER_STOP(this->profilerName()); CCASSERT(nodeVector.empty(), "nodeVector was not empty."); } } , { "clear", [=](){ Vector<Node*> nodeVector = createVector(); CC_PROFILER_START(this->profilerName()); for( int i=0; i<quantityOfNodes; ++i) nodeVector.clear(); CC_PROFILER_STOP(this->profilerName()); CCASSERT(nodeVector.empty(), "nodeVector was not empty."); } } , { "swap by index", [=](){ Vector<Node*> nodeVector = createVector(); int swapIndex1 = quantityOfNodes / 3; int swapIndex2 = quantityOfNodes / 3 * 2; CC_PROFILER_START(this->profilerName()); for( int i=0; i<quantityOfNodes; ++i) nodeVector.swap(swapIndex1, swapIndex2); CC_PROFILER_STOP(this->profilerName()); } } , { "swap by object", [=](){ Vector<Node*> nodeVector = createVector(); Node* swapNode1 = nodeVector.at(quantityOfNodes / 3); Node* swapNode2 = nodeVector.at(quantityOfNodes / 3 * 2); CC_PROFILER_START(this->profilerName()); for( int i=0; i<quantityOfNodes; ++i) nodeVector.swap(swapNode1, swapNode2); CC_PROFILER_STOP(this->profilerName()); } } , { "reverse", [=](){ Vector<Node*> nodeVector = createVector(); CC_PROFILER_START(this->profilerName()); for( int i=0; i<quantityOfNodes; ++i) nodeVector.reverse(); CC_PROFILER_STOP(this->profilerName()); } } , { "c++11 Range Loop", [=](){ Vector<Node*> nodeVector = createVector(); CC_PROFILER_START(this->profilerName()); for (const auto& e : nodeVector) { e->setTag(111); } CC_PROFILER_STOP(this->profilerName()); } } , }; for (const auto& func : testFunctions) { _testFunctions.push_back(func); } }
void TouchesPerformTest3::onEnter() { PerformBasicLayer::onEnter(); auto s = Director::getInstance()->getWinSize(); // add title auto label = LabelTTF::create(title().c_str(), "Arial", 32); addChild(label, 1); label->setPosition(Point(s.width/2, s.height-50)); #define TOUCH_PROFILER_NAME "TouchProfileName" #define TOUCHABLE_NODE_NUM 1000 srand(time(nullptr)); for (int i = 0; i < TOUCHABLE_NODE_NUM; ++i) { int zorder = rand() % TOUCHABLE_NODE_NUM; auto layer = new TouchableLayer(); layer->setTouchEnabled(true); layer->setTouchMode(Touch::DispatchMode::ONE_BY_ONE); addChild(layer, zorder); layer->release(); } auto emitEventlabel = LabelTTF::create("Emit Touch Event", "", 24); auto menuItem = MenuItemLabel::create(emitEventlabel, [](Object* sender){ CC_PROFILER_PURGE_ALL(); std::vector<Touch*> touches; for (int i = 0; i < EventTouch::MAX_TOUCHES; ++i) { Touch* touch = new Touch(); touch->setTouchInfo(i, 10, (i+1) * 10); touches.push_back(touch); } EventTouch event; event.setEventCode(EventTouch::EventCode::BEGAN); event.setTouches(touches); auto dispatcher = EventDispatcher::getInstance(); for (int i = 0; i < 100; ++i) { CC_PROFILER_START(TOUCH_PROFILER_NAME); dispatcher->dispatchEvent(&event, false); CC_PROFILER_STOP(TOUCH_PROFILER_NAME); } CC_PROFILER_DISPLAY_TIMERS(); for (auto& touch : touches) { touch->release(); } }); menuItem->setPosition(Point(0, -20)); auto menu = Menu::create(menuItem, NULL); addChild(menu); }