【发布时间】:2012-08-25 06:48:35
【问题描述】:
我遇到了一个问题,即 Win32 应用程序在调试和发布版本之间存在巨大的性能差异。发布需要 20 秒,而调试构建需要 6 分钟来初始化应用程序。这很痛苦,因为在调试时,在开始做任何事情之前进行初始化总是需要 6 分钟。所以我正在寻找一种方法来调整调试构建中的性能。
运行分析器后,我发现下面的代码是热点。
class CellList {
std::vector<CellPtr>* _cells;
iterator begin() { return (*_cells).begin(); }
iterator end() { return (*_cells).end(); }
reverse_iterator rbegin() { return (*_cells).rbegin(); }
reverse_iterator rend() { return (*_cells).rend(); }
...
}
CellList _cellList = ...;
for (CellList::iterator itr = _cellList.begin(), end = _cellList.end(); itr < end; ++itr) {
Cell* cell = *itr;
if (cell->getFoo()) cell->setBar(true);
else cell->setBar(false);
}
for (CellList::iterator itr = _cellList.rbegin(), end = _cellList.rend(); itr < end; ++itr) {
Cell* cell = *itr;
if (cell->getFoo2()) cell->setBar2(true);
else cell->setBar2(false);
}
这些是时基分析结果中的热点。
std::operator< <std::_Vector_iterator<Cell *,std::allocator<Cell *> >,std::_Vector_iterator<Cell *,std::allocator<Cell *> > >
std::_Vector_const_iterator<Cell *,std::allocator<Cell *> >::operator<
std::reverse_iterator<std::_Vector_iterator<Cell *,std::allocator<Cell *> > >::operator*
std::reverse_iterator<std::_Vector_const_iterator<Cell *,std::allocator<Cell *> > >::reverse_iterator<std::_Vector_const_iterator<Cell *,std::allocator<Cell *> > ><std::_Vector_iterator<Cell *,std::allocator<Cell *> > >
我猜是迭代器操作没有被内联并导致这种巨大的差异。有什么办法可以改善这一点吗?只要还能在源代码中逐行逐行检查所有变量值,我就可以在发布模式下调试。
【问题讨论】:
-
您可以通过将_SECURE_SCL 和_HAS_ITERATOR_DEBUGGING 定义为
0来提高性能。 -
这里有一个关于 _SECURE_SCL 的链接:preshing.com/20110807/the-cost-of-_secure_scl 绝对值得一试!请发回你找到的东西! PS:你在这个列表中添加了多少需要 6++ 分钟的东西?
-
向量中超过 100k,有时超过 1M。
-
我无法在我的项目中添加 _SECURE_SCL=0 和 _HAS_ITERATOR_DEBUGGING=0。在提到的@paulsm4 文章中,两个预处理器都必须在所有源代码中定义,包括预构建库。我无法更改项目中包含的第 3 方库。或者有什么解决方法?
标签: c++ performance debugging visual-studio-2005 profiling