CsO*_*emf 12 c++ templates stl eastl
今天我下载并创建了一个Electronic Arts STL实现的示例项目,EA的矢量看起来比标准慢得多.我刚创建了2个向量并上传了100万个项目:
void performance_test(void)
{
clock_t start;
clock_t end;
// EA
eastl::string strEA = "hello";
eastl::vector<eastl::string> vec_EA;
start = clock();
for (size_t i = 0; i < 1000000; i++)
{
vec_EA.push_back(strEA);
}
end = clock();
printf("EA %f\n", (double(end - start) / 1000));
// Standard
std::string strStandard = "hello";
std::vector<std::string> vec_Standard;
start = clock();
for (size_t i = 0; i < 1000000; i++)
{
vec_Standard.push_back(strStandard);
}
end = clock();
printf("Standard %f\n", (double(end - start) / 1000));
}
Run Code Online (Sandbox Code Playgroud)
结果是:
那么,有什么我做错了或者我错过了什么吗?该示例已使用v100平台工具集进行编译.
Mic*_*urr 14
当我在VS 2010中使用发布版本运行基准测试时,我得到的结果类似于人们可能希望的结果:
EA 0.063000
Standard 0.073000
Run Code Online (Sandbox Code Playgroud)
但是,当我在VS调试器下运行相同的版本构建时,结果会发生显着变化:
EA 1.293000
Standard 0.080000
Run Code Online (Sandbox Code Playgroud)
对于任何对象清理,它需要更长的时间(几十秒).请记住 - 这是相同的发布模式构建,而不是调试构建.
我没有调查过为什么EASTL受到调试器环境的严重影响.我假设它与调试堆有关.
更新(2015年3月4日):
影响结果的另一个细节是所涉及的字符串的长度.VS使用"短字符串优化",std::string其中将减少具有值的字符串对象发生的分配数量"hello".如果更改本例中使用从字符串初始化值"hello"来"hello - but not too short",你会得到结果更像是以下几点:
// release build, run outside of the debugger
EA 0.078000
Standard 0.113000
// release build, run under the debugger
EA 0.762000
Standard 1.414000
Run Code Online (Sandbox Code Playgroud)
现在很明显,在调试器下运行基准测试时的数量级差异很可能是由于调试堆花费了大量时间来跟踪字符串内存分配.
| 归档时间: |
|
| 查看次数: |
8196 次 |
| 最近记录: |