map<int, GCCollectedInfo*>::iterator it_cltd = m_gcColtedInfoMap->find(locatn);
if (it_cltd != m_gcColtedInfoMap->end())
{
vector<ObjectID>::iterator findIter = find(it_cltd->second->m_gcCollectedlist2->begin(), it_cltd->second->m_gcCollectedlist2->end(), objectID);
if (findIter != it_cltd->second->m_gcCollectedlist2->end())
{}
}
我在我的回调方法中写了这行代码,大概我的 vector 大小是50000(或多或少)。当我尝试在我的应用程序中使用此代码时,加载时间比正常情况下多了 20 秒。有没有其他方法可以在 vector 或列表中查找元素?
最佳答案
如果每 50000 个查找是规则的,那么最好排序并使用 std::binary_search
关于c++ - find() 方法获取搜索时间- C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45012223/