GCC最近發布了4.5版本,對于C++的支持除了更為豐富的0x特性支持外(參考
這里),
還增加了一個新的profile模式(尚處于試驗階段),可以根據程序運行狀態給出關于STL使用的一些優化建議。
參看如下的描述:
-
An experimental
profile mode has been added. This is an implementation of
many C++ standard library constructs with an additional analysis
layer that gives performance improvement advice based on
recognition of suboptimal usage patterns. For example,
#include <vector>
int main()
{
std::vector<int> v;
for (int k = 0; k < 1024; ++k)
v.insert(v.begin(), k);
}
When instrumented via the profile mode, can return suggestions about
the initial size and choice of the container used as follows:
vector-to-list: improvement = 5: call stack = 0x804842c ...
: advice = change std::vector to std::list
vector-size: improvement = 3: call stack = 0x804842c ...
: advice = change initial container size from 0 to 1024
These constructs can be substituted for the normal libstdc++
constructs on a piecemeal basis, or all existing components can be
transformed via the -D_GLIBCXX_PROFILE
macro.
這個profile mode的主要作用就是根據代碼實際運行狀況給出關于STL的使用優化建議。有點遺憾的是,該profile方法是intrusive的,必須添加-D_GLBCXX_PROFILE來重新編譯所有的代碼。
Profile mode的提出源于09年CGO的一篇
paper,作者里邊出現了華人的名字(根據拼音來判斷);作者地址填的顯然是Purdue大學的:
Dept. of Comput. Sci., Purdue Univ., West。
GCC的Profiler對C++的支持一貫停留在和C同樣的水平;由于C++模板機制和OO的存在使得很多時候分析profiling結果的意義被大大削弱。
這個針對STL的profile mode還是很值得期待的。