C++ visualc&x2B+;2015年标准::无序机组性能
我编写了一个非常简单的程序来测试C++ visualc&x2B+;2015年标准::无序机组性能,c++,c++11,visual-c++,unordered-set,C++,C++11,Visual C++,Unordered Set,我编写了一个非常简单的程序来测试std::setvsstd::unordered\u set的性能。当我在GCC上运行这个程序时,无序集要快得多。但是如果在Visual C++ 2015上运行相同的代码,则代码> SET明显优于未排序的SETSE/ 我错过了什么明显的东西吗?我在VisualC++中搜索了任何关于“代码>未排序EDSET/的性能问题,但我没有发现任何东西。当然,我在发布模式下运行,所有通常的优化都已打开 这里是结果,第一列与调用insert的次数成比例,set是第二列,unord
std::set
vsstd::unordered\u set
的性能。当我在GCC上运行这个程序时,无序集
要快得多。但是如果在Visual C++ 2015上运行相同的代码,则代码> SET明显优于insert
的次数成比例,set
是第二列,unordered\u set
是第三列。计时单位为微秒,越低越好
// with GCC 4.9.2
1 23.208 11.323
2 31.705 10.805
3 41.113 11.671
4 51.124 12.742
5 60.941 13.931
6 69.642 14.083
7 75.245 15.151
8 84.227 15.983
9 93.464 17.415
10 102.419 18.036
11 121.212 19.979
12 129.748 20.908
13 140.378 22.201
14 151.061 23.131
15 151.483 23.289
16 162.107 24.252
17 170.408 24.746
18 175.369 25.73
19 184.257 26.835
20 192.877 29.459
21 214.805 30.461
22 223.105 30.977
23 221.382 31.037
24 230.129 32.398
// with Visual C++ 2015
1 24.761 32.473
2 31.075 47.305
3 39.309 58.974
4 44.749 73.753
5 51.608 81.204
6 58.141 96.035
7 67.309 106.105
8 75.653 118.712
9 80.801 126.99
10 88.548 144.899
11 95.388 165.135
12 105.546 170.017
13 108.9 177.442
14 117.891 192.446
15 125.177 194.573
16 130.842 212.399
17 138.182 242.828
18 144.113 240.621
19 151.28 262.748
20 158.495 265.814
21 168.463 277.699
22 178.542 295.593
23 181.643 304.112
24 191.779 317.013
这是我写的代码:
#include <iostream>
#include <set>
#include <unordered_set>
#include <chrono>
template<typename T>
T InsertTest(const int count, const int repeat)
{
T set;
for (int k = 0; k < repeat; ++k)
{
for (int i = 0; i < count; ++i)
{
set.insert(i * (repeat + 1));
}
}
return set;
}
int main()
{
for (int repeat = 1; repeat < 25; ++repeat)
{
std::cout << repeat << '\t';
{
const auto beg = std::chrono::high_resolution_clock::now();
InsertTest<std::set<int>>(100000, repeat);
const auto end = std::chrono::high_resolution_clock::now();
std::cout << std::chrono::duration_cast<std::chrono::microseconds>(end - beg).count() / 1000.0f << '\t';
}
{
const auto beg = std::chrono::high_resolution_clock::now();
InsertTest<std::unordered_set<int>>(100000, repeat);
const auto end = std::chrono::high_resolution_clock::now();
std::cout << std::chrono::duration_cast<std::chrono::microseconds>(end - beg).count() / 1000.0f << '\t';
}
std::cout << std::endl;
}
}
#包括
#包括
#包括
#包括
模板
T插入测试(常数整数计数,常数整数重复)
{
T集;
对于(int k=0;k std::您是否可以在发布模式下启动程序而不进行调试?是的,我启动了,在发布模式下编译,然后在IDE之外运行。我无法在我的计算机上复制它(VS2015更新1,发布版本,x86和x64)。例如,我的最后一行是24163.47979.866
@blastfurny interest!我正在运行VS2015 REL,我将对此进行调查。我无法复制,但一致地,无论是否使用MSVC 2015进行优化,哈希集都会稍微快一点。而使用g++则会快两到三倍。